0

我有下表

+-----+------+
| sID | name |
+-----+------+
|   2 | MXX  |
|   3 | ISS  |
|   4 | FSS  |
|   5 | SSA  |
|   6 | PSA  |
+-----+------+

和下表

+-----+-------+
| sID | pname | 
+-----+-------+
|   1 | qqq   |      
|   1 | yyy   |         
|   2 | zzz   |
|   1 | lll   |
|   2 | mmm   | 
|   3 | ttt   |
|   3 | sss   |
|   5 | xxx   |
|   5 | iii   |
+-----+-------+

并且连接结果应该看起来像

+-----+-------+----------+
| sID | pname | supplier |
+-----+-------+----------+
|   1 | qqq   |          |
|   1 | yyy   |          |
|   2 | zzz   | MXX      |
|   1 | lll   |          |
|   2 | mmm   | MXX      |
|   3 | ttt   | ISS      |
|   3 | sss   | ISS      |
|   5 | xxx   | SSA      |
|   5 | iii   | SSA      |
+-----+-------+----------+

想法是将第一个表中的列值放在name第二个表中sID相同的位置

我试过Select * From TABLE1 c LEFT join TABLE2 T on c.sID=T.sID

4

1 回答 1

4

你的左连接是错误的方式。

 select table2.sid, pname, table1.name as supplier 
 from table2  
    left join table1 on table2.sid = table1.sid 

或将您的更改left joinright join

于 2012-10-24T11:09:09.807 回答