如何將兩個表連接在一起以獲取所有行,然後輸入NULL,其中一個在另一箇中缺失。左/右連接以接收所有行
例如:
declare @t1 table (x int)
declare @t2 table (x int)
insert into @t1 select 2
insert into @t1 select 3
insert into @t1 select 4
insert into @t1 select 5
insert into @t2 select 1
insert into @t2 select 2
insert into @t2 select 5
select *
from @t1 t1
left join @t2 t2 on t2.x = t1.x
結果應該是這樣的:
t1.x t2.x
NULL 1
2 2
3 NULL
4 NULL
5 5
['FULL OUTER JOIN'](http://stackoverflow.com/questions/34719640/left-right-join-to-receive-all-rows) –