Sql语句not in不会利用索引所以效率十分低,在存储过程中使用not in 和not exists前者要花后者上百倍的时间,not in 能直接对null进行判断处理,而not exists 则需要手动进行处理,如果not exists处理的字段中有null的话则可以用
SELECT *from 表一 where not EXISTS(
select 1 from 表二 D3 where (((字段一 is not null and 字段二 is not null and 字段一 = 字段二)
or
(字段一 is null and 字段二 is null))))
来处理字段里面有null的情况,如果不这样进行处理的话 null和null被判断为不相等的。
SQL优化,not in和not exists
最新推荐文章于 2023-08-22 11:38:02 发布