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中的,请问是什么原因?如何才能查出真正的结果?

解决方案 »

  1.   

    select * from a_Info where id is null;//0条记录  a_info ?
      

  2.   

    写错了,不是‘a_Info’,是a。
      

  3.   

    select * from a where id not in(select id from b);//0条记录 
    其中五条记录与288条中记录重复了,所以为0
      

  4.   

    select * from a where id not in(select b.id from b)
    试试
      

  5.   

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

  6.   

    重复的也会显示的。
    select id, count(id) from b group by id having count(id) > 1//依然是0条记录
      

  7.   

    select * from a where id not in(select id from b);//0条记录 
    剩下的5条记录重复的
      

  8.   

    像這種情況我就不會用這種寫法
    not in的效率也是不高的select a.id from a left join b on a.id=b.id  where b.id is null
      

  9.   

    try:select * from a left join  b on a.id = b.id where b.id is null
      

  10.   


    虽然查出了不存在的数据,但为什么not in语法查不出来? 有bug嘛?
      

  11.   


    虽然查出了不存在的数据,但为什么not in语法查不出来? 有bug嘛?
    为什么? 几种办法都可以了, 但为什么not in 不行? 什么原因?
      

  12.   

    不晓得原因哦,不过我一般都用exist的
      

  13.   

    sql的逻辑值有三种:true false unknown
    not in 的是时候可能是a,b表里面有null值,null=null的判断返回unknown,那么对应的b表里面就选不出来