select id  from t1 where id not in (select id from t2 where id is not null)

解决方案 »

  1.   

    你的记录的ID是什么,到T2中查查是不是真的没有.
      

  2.   

    not in 有null的缺陷,你要用is null去掉null值就可以了。
      

  3.   

    select  a.id,b.id 
    from t1 a left join t2 b on ti.id=t2.id 
    where t2.id is null
    也就是A.ID为NULL的记录也会被查出来
    而select a.id  
    from t1 a
     where a.id not in (select b.id from t2 b )
    如果A.id为NULL,而且也有B.id为NULL,就不会被查出.其实应该是LEFT JOIN无法被关联产生的NULL和本来的NULL,所以一就多出那来就是NULL的数据来了.
      

  4.   

    not in 效率不低,
    有贴子说 in 子查询比join 效率要高。