如何将两个表连接在一起以获取所有行,然后输入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) –