表A
ID NAME
1    A1
2    A2
3  A3

表B
ID AID NAME
1    1 B1
2    2 B2
3    2 B3

SELECT ID,NAME FROM A WHERE EXIST (SELECT * FROM B WHERE A.ID=B.AID)

等价于 select id.name from A where A.ID IN (SELECT B.ID FROM B)
执行结果为
1 A1
2 A2

NOT EXISTS 就是反过来
SELECT ID,NAME FROM A WHERE NOT EXIST (SELECT * FROM B WHERE A.ID=B.AID)
执行结果为
3 A3

应用场景:

--不等于
select * from udf_user u where not exists (
        select * from armc_user_team t where t.user_name=u.username_ and t.team_code='DCCDJP'
        )
        
 --同时存在
 select * from armc_user_team t where t.team_code='a'
 and exists(select * from armc_user_team t1 where t1.user_name=t.user_name and t1.team_code='b')
        
 

exists和not exists关键字的更多相关文章

  1. oracle中的exists 和not exists 用法 in与exists语句的效率问题

    博文来源(oracle中的exists 和not exists 用法):http://chenshuai365-163-com.iteye.com/blog/1003247 博文来源(  in与exi ...

  2. (转)sql中 in 、not in 、exists、not exists 用法和差别

    exists (sql 返回结果集为真)  not exists (sql 不返回结果集为真)  如下:  表A  ID NAME  1    A1  2    A2  3  A3 表B  ID AI ...

  3. MySQL exists 和 not exists 的用法

    有一个查询如下: 1 SELECT c.CustomerId, c.CompanyName   2 FROM Customers c   3 WHERE EXISTS(   4     SELECT  ...

  4. 转【】浅谈sql中的in与not in,exists与not exists的区别_

    浅谈sql中的in与not in,exists与not exists的区别   1.in和exists in是把外表和内表作hash连接,而exists是对外表作loop循环,每次loop循环再对内表 ...

  5. 浅谈sql中的in与not in,exists与not exists的区别

    转 浅谈sql中的in与not in,exists与not exists的区别   12月12日北京OSC源创会 —— 开源技术的年终盛典 »   sql exists in 1.in和exists ...

  6. MySQL 子查询 EXISTS 和 NOT EXISTS(转)

    MySQL EXISTS 和 NOT EXISTS 子查询 MySQL EXISTS 和 NOT EXISTS 子查询语法如下: SELECT ... FROM table WHERE EXISTS ...

  7. MySQL 子查询 EXISTS 和 NOT EXISTS

    MySQL EXISTS 和 NOT EXISTS 子查询 MySQL EXISTS 和 NOT EXISTS 子查询语法如下: SELECT ... FROM table WHERE EXISTS ...

  8. Mysql数据库中的EXISTS和NOT EXISTS

    SQL语言中没有蕴含逻辑运算.但是,可以利用谓词演算将一个逻辑蕴含的谓词等价转换为:p->q ≡┐p∨q. 我们通过一个具体的题目来分析:(具体的表和数据详见文章:Mysql数据库中的EXIST ...

  9. sql中 in 、not in 、exists、not exists 使用方法和区别

    % 的一类. NOT IN:通过 NOT IN keyword引入的子查询也返回一列零值或很多其它值. 以下查询查找没有出版过商业书籍的出版商的名称. SELECT pub_name FROM pub ...

  10. [20180808]exists and not exists.txt

    [20180808]exists and not exists.txt --//生产系统遇到的一个性能问题,通过例子来说明: 1.环境:SCOTT@test01p> @ ver1 PORT_ST ...

随机推荐

  1. 阿里面试Java程序员都问些什么?

    刚开始也是小白,也是一步步成成起来的.需要提的一点是,你将来是需要靠这个吃饭的,所以请对找工作保持十二分的热情,而且越早准备越好. 阿里一面 一面是在上午9点多接到支付宝的面试电话的,因为很期望能够尽 ...

  2. 作业day2

    问题一: Java类中只能有一个公有类吗?用Eclipse检测以下程序是否正确.是否在接口中同样适用. 因为公共类名必须和这个java源程序文件名相同,所以只能有一个公共类,相应的,main方法作为程 ...

  3. puthon 字典的 .update() 方法

    1.可以直接更新字典 2.也可以用等号连接,更新一个可迭代对象.

  4. [PAT] A1021 Deepest Root

    [题目大意] 给出n个结点和n-1条边,问它们能否形成一棵n个结点的树,如果能,从中选出结点作为树根,使整棵树的高度最大.输出所有满足要求的可以作为树根的结点. [思路] 方法一:模拟. 1 连通.边 ...

  5. PWA - service worker - Workbox(未完)

    Get Started(开始) 只有get请求才能cache缓存吗? Create and Register a Service Worker File(创建和注册 Service Worker) B ...

  6. Linux 常用命令 服务器间scp 用户 export 创建文件、软连接

    获取外网ip curl icanhazip.com 服务器间的 文件 复制 scp root@ip:/源目录 目标目录 软连接 查看软连接 ls -li 创建软连接 ln -s 源文件 目标文件 -s ...

  7. jQuery中校验时间格式的正则表达式小结

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  8. Dubbo-服务注册中心之AbstractRegistry

    在dubbo中,关于注册中心Registry的有关实现封装在了dubbo-registry模块中.提供者(Provider)个消费者(Consumer)都是通过注册中心进行资源的调度.当服务启动时,p ...

  9. C++->以读或写方式打开一个文件

    以读或写方式打开一个文件 #include<iostream.h>   //.h以C|非C标准引用库文件 #include<fstream.h> #include<std ...

  10. 15. 3Sum、16. 3Sum Closest和18. 4Sum

    15 3sum Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = ...