34,838
社区成员




if not object_id('ta') is null
drop table ta
Go
Create table ta([ID] int)
Insert ta
select 1 union all
select 2 union all
select 3 union all
select 4 union all
select 5
Go
if not object_id('tb') is null
drop table tb
Go
Create table tb([ID] int,[NAME] nvarchar(2))
Insert tb
select 2,N'AA' union all
select 4,N'BB' union all
select 5,N'CC'
Go
select a.id,
isnull(b.name,'')[name]
from ta a left join tb b
on a.id=b.id
/*
id name
----------- ----
1
2 AA
3
4 BB
5 CC
(5 row(s) affected)
*/
select a.id,
b.name
from ta a left join tb b
on a.id=b.id