zoukankan      html  css  js  c++  java
  • SQL in, not in, exists, not exists

    网上很多人在讨论In和Exists的性能对比,本人也搞不懂哪个性能更佳,只是一般在小表中用In,而在大表中用Exists。下面只是举例如果使用,以勉被喷了。

    1、In。

    1 select * from table1 a
    2 where a.Id in (select Id from table2)
    3 
    4 select * from table1 a
    5 where a.Id not in (select Id from table2)

    2、Exists。

     1 select * from QVS_CUSTPACKINGSLIPPRINTJOUR a
     2 where exists 
     3 (select PRINTID from QVS_CustPackingSlipPrintTrans b 
     4 where a.PRINTID = b.PRINTID and b.DATAAREAID in ('QCN'))
     5 and a.DATAAREAID in ('QCN')
     6 
     7 select * from QVS_CUSTPACKINGSLIPPRINTJOUR a
     8 where not exists 
     9 (select PRINTID from QVS_CustPackingSlipPrintTrans b 
    10 where a.PRINTID = b.PRINTID and b.DATAAREAID in ('QCN'))
    11 and a.DATAAREAID in ('QCN')
  • 相关阅读:
    装饰器和表达生成式
    函数
    字符编码
    函数基础
    列表,字典与集合
    Linux Semaphore
    tp5安装easyWeChat
    wx.request
    小程序设计规范
    小程序的概念和特点
  • 原文地址:https://www.cnblogs.com/Jinnchu/p/2668261.html
Copyright © 2011-2022 走看看