• 20191225_关于sql中exists和not exists


    exists
    n. 存在量词(exist的复数)
    v. 存在;出现;活着(exist的三单形式)

    理所当然 not exists 就是不存在

    那么 if  exists 就是表示它引导的子句有结果集返回就是真, not exists 表示它引导的子句没有结果返回就是真; 这两种情况, 都是针对的是否有结果返回, 而不管返回的结果是什么;

    示例:

    select * from  sys_User where id=1

     exists表示存在就为true, 下面的示例输出消息aaa

    if   exists(select * from  sys_User where id=1)
    begin
    print 'aaaa'
    end

    not exists表示不存在为true, 否则为false

    if not  exists(select * from  sys_User where id=111111111)
    begin
    print 'aaaa'  --没有这个id则会输出 , 因为查到的结果集是空
    end

    exists和in的区别 (另外的 not exists 和not in的区别是一样的)

    select * from sys_User where  user_no in (select user_no,[user_name] from sys_User where [user_name] like '%a%')

    select * from sys_User where exists (select user_no,[user_name] from sys_User where [user_name] like '%a%')

  • 相关阅读:
    IOC / AOP
    Volatile
    观察者模式
    Gang Of Four的23中设计模式
    适配器模式
    享元模式
    设计模式
    B树和B+树
    Java内存模型(JMM)
    【Java的IO流之文件字符输入输出流 25】
  • 原文地址:https://www.cnblogs.com/wxylog/p/12099036.html
Copyright © 2020-2023  润新知