当前位置: 代码迷 >> Sql Server >> 关于not in 有关问题
  详细解决方案

关于not in 有关问题

热度:41   发布时间:2016-04-27 13:30:03.0
关于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_Nowhere b.Piece_No is null
------解决方案--------------------
SQL code
--可以使用not exists代替not in,楼主试试有没有结果:select * from tb awhere not exists(select 1 from tb b where a.Piece_No=b.Piece_No)
  相关解决方案