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的数据来了.
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的数据来了.
有贴子说 in 子查询比join 效率要高。