SQL语句Not IN优化方案

总结网友们在CSDN社区上对于not in的优化策略,整理如下,备查。 
 
select * from emp where emp_no not in (select emp_no from emp_bill)
要求用两种 SQL 写法优化上面 SQL 。
 
方法一、
 
select *
 
       from emp a
 
        where   not exists ( select 1
 
       from emp_bill b
 
          where b.emp_no = a.emp_no)
 
方法二、
 
select * from
 
(select a.*,b.* from emp a left join emp_bill b on b.emp_no = a.emp_no)
 
where trim(b.emp_no) is null or trim(b.emp_no) = ''
 
 
外连接效率最好, Not Exists 其次, Not in 最低
原文地址:https://www.cnblogs.com/hachun/p/4097964.html