读书人

关于not in 有关问题

发布时间: 2012-04-14 17:14:21 作者: rapoo

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

读书人网 >SQL Server

热点推荐