34,590
社区成员
发帖
与我相关
我的任务
分享
if OBJECT_ID('tab1') is not null drop table tab1
create table tab1
(name varchar(10), [count] int)
if OBJECT_ID('tab2') is not null drop table tab2
create table tab2
(name varchar(10), [count] int)
insert tab1 select 'A',1
insert tab1 select 'B',1
insert tab2 select 'A',NULL
insert tab2 select 'B',NULL
insert tab2 select 'C',NULL
insert tab2 select 'D',NULL
select tab2.name,isnull(tab1.[count],0) as [count]
from tab2
left join tab1 on tab2.name=tab1.name
name count
---------- -----------
A 1
B 1
C 0
D 0
(4 行受影响)
select tab2.name,isnull(tab1.[count],0) as [count]
from tab2
left join tab1 on tab2.name=tab1.name
select
tab2.name,isnull(tab1.[count],0) as [count]
from
tab2
left join tab1 on
tab2.name=tab1.name