zoukankan      html  css  js  c++  java
  • 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 最低
  • 相关阅读:
    foreach
    if
    注意事项
    Maven测试
    课程评价
    个人总结
    HTML表格CSS美化
    让多个输入框对齐
    CSS样式写在JSP代码中的几种方法
    日常
  • 原文地址:https://www.cnblogs.com/hachun/p/4097964.html
Copyright © 2011-2022 走看看