zoukankan      html  css  js  c++  java
  • sql中in/not in 和exists/not exists的使用方法差别

    1;首先来说in/not in的使用方法

          in/not in是确定单个属性的值是否和给定的值或子查询的值相匹配;
     

         select * from Student s where s.id in(1,2,3);
    
         select * from Student s where s.name in( select distinct name from Project)
    
    2。如今来说exists/not exists的使用方法
       exists/not exists是解决两张表的交集和差集
    
    
       select * from proj_basic_info p  where   not exists (select * from proj_basic_info q where   p.id=q.id and q.proj_type=1 and q.qy_source='SUAEE')
    
       select * from proj_basic_info p  where  exists (select * from proj_basic_info q where   p.id=q.id and q.proj_type=1 and q.qy_source='SUAEE')

    总结:假设是推断单个属性是是否匹配时。就选in/not in;假设是推断多个属性时,即能够看做集合时。就选用exitst /not exists。

    
    
    
    

  • 相关阅读:
    Windows下安装redis
    flask-redirect
    MySQLHelper
    配置信息
    注释习惯
    SQL2012 附加数据库提示5120错误解决方法
    Union-SQL Server学习笔记
    存储过程
    模糊查询&&日期时间操作
    数据库表的设计
  • 原文地址:https://www.cnblogs.com/liguangsunls/p/6793069.html
Copyright © 2011-2022 走看看