首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

关于not in 有关问题

2012-04-14 
关于not in 问题selecta.*from awhere a.Piece_No not in(select Piece_No from b)表a中的Piece_No 等于

关于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) 

热点排行