我正在使用两张表,两张表都有一个同名的id列,我需要找到一种方法将一张表的id合并到另一张表中,用一个新的列名。
Table 1
Houses
--------------------------------------
| ID | Address
--------------------------------------
| 1 | 123 Main
| 2 | 234 Center
| 3 | 345 North Street
Table 2
Houses that are blue
--------------------------------------
| ID | Address
--------------------------------------
| 2 | 234 Center
Resultant table:
Houses
--------------------------------------
| ID | Address | BlueHouseID
--------------------------------------
| 1 | 123 Main | NULL
| 2 | 234 Center | 2
| 3 | 345 North | NULL
谢谢你在设置这个查询上的任何帮助。这个最终将被放在一个覆盖的文本文件中,以便以后的摄取。
2条答案
按热度按时间bvpmtnay1#
使用 "left join"。
nafvub8i2#
只是 "向左加入"。
或者你想在地址上匹配,而不是在
id
上匹配。