日期:2014-05-18  浏览次数:20447 次

关于not in 问题
select 
  a.*
from a 
  where a.Piece_No not in
  (select Piece_No from b)

表a中的Piece_No 等于 表b 中的Piece_NO

如果表a中的数据做了扫描,数据插入到表b中。

想查找漏扫描数据,即在表a中出现但不在表b中出现的数据,用以上语句,结果却列出所有的数据。

------解决方案--------------------
SQL code
select * from a left join b on a.Piece_No =b.Piece_No
where b.Piece_No is null

------解决方案--------------------
SQL code

--可以使用not exists代替not in,楼主试试有没有结果:
select * from tb a
where not exists(select 1 from tb b where a.Piece_No=b.Piece_No)