读书人

not in 与 left join 的结果不同可能

发布时间: 2012-01-30 21:15:58 作者: rapoo

not in 与 left join 的结果不同,可能是什么原因哦,解决马上给分
select * from a where id not in (select distinct id from b)
返回空集
select * from a left join b on a.id=b.id where b.id is null
返回很多

有点迷惑,还没找到原因,大虾给指点下啊


[解决办法]
select * from a where id not in (select distinct id from b)
改成:
select * from a where id not in (select distinct id from b WHERE id IS NOT NULL)

[解决办法]
a表或b表中的id有null值?

读书人网 >SQL Server

热点推荐