在路上

导航

null 不参与in 和= 运算

题目写的不清楚,献上例子

create table tb1
(tid int primary key,
tname nvarchar(200) null)
go
insert into tb1
select 1,'aa'
go
insert into tb1
values(2,null)
go

select * into tb2 from tb1
go

 这是两个表长的一样,都有两条记录,然后运行

select * from tb1 where tname  in (select tname from tb2)
go
select * from tb1 where tname not in (select tname from tb2)
go
select * from tb1 where not exists(select 1 from tb2 where isnull(tb2.tname,'1')=isnull(tb1.tname,'1'))
go
select * from tb1 where not exists(select 1 from tb2 where tb2.tname=tb1.tname)
go
select * from tb1 left join tb2 on tb1.tname=tb2.tname where tb2.tid is null
go

根据结果说明,即使两列结构相同,都有null值,也无法=出来;同时,in 与not in都出不来

posted on 2012-09-16 18:02  Clarence Yang  阅读(940)  评论(0)    收藏  举报