今天发现了一个sql的小问题
这里有三条sql语句,想找到存在tblA中,却又不在tblB中的记录数
select count( *) from tblA
select count(*) from tblA where pid in ( select pid from tblB)
select count(*) from tblA where pid not in ( select pid from tblB)
select count(*) from tblA where pid in ( select pid from tblB)
select count(*) from tblA where pid not in ( select pid from tblB)
10,7,0
后来才发现最后一句应该这样写
select count(*) from tblA where pid not in (select pid from tblB where pid is not null)
运行后的结果才对:10,7,3
只是不知道为什么最后一句不取掉空项就select 不出来