zoukankan      html  css  js  c++  java
  • 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%')

  • 相关阅读:
    Python基础知识2-内置数据结构(上)
    vs code的快捷方式
    vs code配置
    vs code安装
    web浏览器兼容问题
    js正則表達式
    MVC MVP MVVM
    vue-cli(vue脚手架)
    web攻擊
    web前端面試題
  • 原文地址:https://www.cnblogs.com/wxylog/p/12099036.html
Copyright © 2011-2022 走看看