select * from a;//293条记录
select * from b;//296条记录
select * from a_Info where id is null;//0条记录
select * from b where id is null;//0条记录
select * from a where id in(select id from b); //288条记录
select * from a where id not in(select id from b);//0条记录
select * from a, b where a.id = b.id ;//288条记录为什么not in那个sql的结果是0条记录? 不是应该为293 - 288 = 5条记录 才对嘛?
我通过逐行查看数据,的确是有a.id 不在 b.id中的,请问是什么原因?如何才能查出真正的结果?
其中五条记录与288条中记录重复了,所以为0
试试
select id, count(id) from b group by id having count(id) > 1//依然是0条记录
剩下的5条记录重复的
not in的效率也是不高的select a.id from a left join b on a.id=b.id where b.id is null
虽然查出了不存在的数据,但为什么not in语法查不出来? 有bug嘛?
虽然查出了不存在的数据,但为什么not in语法查不出来? 有bug嘛?
为什么? 几种办法都可以了, 但为什么not in 不行? 什么原因?
not in 的是时候可能是a,b表里面有null值,null=null的判断返回unknown,那么对应的b表里面就选不出来