读书人

有关使用“IN”时查找不完全的有关问题

发布时间: 2012-01-14 20:02:35 作者: rapoo

有关使用“IN”时查找不完全的问题
请问一下是否有人遇到过在使用“in”的时候有查询不完全的情况。。
如果in的结果集很大,有上百万的数据,那么在查询或者删除的时候就会出现不完全的现象。

比如:delete from table1 where col001 in
(select * from table2 where left(col001,7)
in (select col001 from table3 )))

table3里面有10万条记录,table2里面有100万条记录,table1里面也有100万条记录。这样删除是不是会出现查找不完全的现象阿?




[解决办法]
比如:delete from table1 where col001 in
(select * from table2 where left(col001,7)
in (select col001 from table3 )))

table3里面有10万条记录,table2里面有100万条记录,table1里面也有100万条记录。这样删除是不是会出现查找不完全的现象阿?
-------------------

没试过,,,
delete t1 from table1 t1
where exists(select 1 from table3 t3 where col001=left(t1.col001,7))
and exists(select 1 from table2 where col001=t1.col001)

读书人网 >SQL Server

热点推荐