谈NOT IN和Exists

 表1: test001

select * from test001

表2:test002

select * from test002

执行语句:

select * from test002 where id not in(select id from test001)

居然没有结果?

原因:因为test001表中有id为空

解决方法:

方法一:

select * from test002 where id not in(select id from test001 where id is not null)

方法二:

select * from test002 a where not exists (select 1 from test001 b where b.id=a.id)

 

参考网址:
http://x-spirit.iteye.com/blog/615603

posted on 2015-01-01 14:22  modDx  阅读(173)  评论(0编辑  收藏  举报

导航