0

this is an illustration of what I need to do..

TABLE 1

  `----------
    ID     VALUE

    123    A

    123    B

    123    C

    123    D

    123    E

    123    F

    ----------`

TABLE 2

----------
ID        VALUE    STATUS

123        A       POSTED

123        B       POSTED

123        C       CANCEL

----------

OUTPUT

----------
VALUE     ID

A         POSTED

B         POSTED

C         CANCEL

D

E

F

----------

When I search for the ID, everything that has the ID in TABLE 1 needs to be shown when it has a duplicate in table 2 information that does not exist in TABLE1 should merge to be shown in an OUTPUT TABLE... I can only search using the ID

can anyone give me a headstart on how to achieve this in php., mysql is the database ., Im new to this., thanks in advance.. :)

the tables are from two different databases..

4

4 回答 4

1
select t1.id, t1.value,t2.status from table1 t1 
left join table2 t2 on 
t1.value = t2.value where t1.id = <urID>

小提琴

如果表在两个数据库上:

select t1.id, t1.value,t2.status from db1.table1 t1 
left join db2.table2 t2 on 
t1.value = t2.value where t1.id = <urID>
于 2013-07-26T07:14:11.910 回答
0

试试这个

select * from table1 as tbl1 left join table2 as tbl2 on tbl1.id = tbl2.id and tbl1.value = tbl2.value

于 2013-07-26T07:16:20.507 回答
0

您需要连接两个表(您的连接条件是 id 和 value)。因此,我们根据该标准加入表格并选择

select table1.id, table1.value, table2.status from table1 inner join table2 on (table1.id=table2.id AND table1.value=table2.value)

在 Where 子句中加入之后,您可以指定您的条件

喜欢,

select table1.id, table1.value, table2.status from table1 inner join table2 on (table1.id=table2.id AND table1.value=table2.value) WHERE table.id = 123
于 2013-07-26T07:14:26.240 回答
0

我认为LEFT JOIN需要一个简单的

SELECT TABLE_1.VALUE,TABLE_2.STATUS FROM TABLE_1 LEFT JOIN TABLE_2 ON TABLE_1.ID = TABLE_2.ID


SELECT D1.TABLE_1.VALUE, D2.TABLE_2.STATUS FROM D1.TABLE_1 LEFT JOIN D2.TABLE_2 ON D1.TABLE_1.ID = D2.TABLE_2.ID

于 2013-07-26T07:15:04.877 回答