我有这样的表的列表:合并多个表共享列
T1
ID | Name
3 | 'AAA'
4 | 'BBB'
5 | 'CCC'
6 | 'DDD'
7 | 'EEE'
T2
ID | Password
3 | 'test'
6 | 'password'
T3
ID | Birth Year | Last Name
4 | 1990 | 'John'
6 | 1988 | 'Megan'
7 | - | 'Bob'
T4
ID | Birth Year
7 | 1985
我想将它们全部合并到这里,注意到t3和t4都有出生年份列,但该值只会出现在任意一列中。
ID | Name | Password | Birth Year | Last Name
3 | 'AAA' | 'test' | - | -
4 | 'BBB' | - | 1990 | 'John'
5 | 'CCC' | - | - | -
6 | 'DDD' |'password'| 1988 | 'Megan'
7 | 'EEE' | - | 1985 | 'Bob'
有谁知道如何可以做到这一点? t1是“主”表,因此它将始终包含所有ID。
我已经试过:
select * \
from t1 \
LEFT outer join t2 on t1.ID = t2.ID \
LEFT outer join t3 on t1.ID = t3.ID \
LEFT outer join t4 on t1.ID = t4.ID
但它不正常工作,它在T1,T2,T3每个单独列单独的列,T4
你需要OUTER JOIN。例如:t1左外连接t2左外连接t3左外连接t4。 –
看到这个:https://stackoverflow.com/questions/38549/what-is-the-difference-between-inner-join-and-outer-join –
我将修改我@AlKepp – Joe