22,210
社区成员
发帖
与我相关
我的任务
分享
declare @B table (empno int)
insert into @B
select 40001 union all
select 40002
select * from @B where empno='40001' --在B表是可以检索出数据的,
/*
empno
-----------
40001
*/
declare @A table (empno int)
insert into @A
--select null union all
select 40003
select * from @A where empno='40001'--在A表中查不出任何数据
/*
empno
-----------
(0 row(s) affected)
*/
--把A表中的null去掉,结果就有了
select * from @B where empno not in (select empno from @A)
/*
empno
-----------
40001
40002
*/
declare @B table (empno int)
insert into @B
select 40001 union all
select 40002
select * from @B where empno='40001' --在B表是可以检索出数据的,
/*
empno
-----------
40001
*/
declare @A table (empno int)
insert into @A
select null union all
select 40003
select * from @A where empno='40001'--在A表中查不出任何数据
/*
empno
-----------
(0 row(s) affected)
*/
select * from @B where empno not in (select empno from @A)
/*
empno
-----------
(0 row(s) affected)
*/
--try
select *
from b t
where not exists(select 1 from a where empno=t.empno)