首页 > 数据库技术 > 详细

SQL语句Not IN优化方案

时间:2014-11-14 19:41:18      阅读:283      评论:0      收藏:0      [点我收藏+]
总结网友们在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 a.*
 
       from emp a ,emp_bill b
 
       where a.emp_no=b.emp_no(+)
 
             and b.emp_no is null
 
方法二继续优化、
 
select a.*
 
       from emp a ,emp_bill b
 
       where a.emp_no=b.emp_no(+)
 
             and NVL(b.emp_no, ‘1‘) = ‘1‘ 
 
表连接效率最好, Not Exists 其次, Not in 最低

SQL语句Not IN优化方案

原文:http://www.cnblogs.com/hachun/p/4097964.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!