欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Oracle: minus | in | exists

程序员文章站 2022-05-07 16:46:02
...
解释及例子:
MINUS Query:
http://www.techonthenet.com/sql/minus.php

IN Function:
http://www.techonthenet.com/sql/in.php

EXISTS Condition:
http://www.techonthenet.com/sql/exists.php


实例代码:
引用
SQL> select distinct deptno from dept

    DEPTNO
----------
        10
        20
        30
        40

4 rows selected.
SQL> select distinct deptno from emp

    DEPTNO
----------
        30
        20
        10

3 rows selected.
SQL> select distinct  deptno from dept  
where deptno in  
(select distinct deptno from emp)

    DEPTNO
----------
        30
        20
        10

3 rows selected.
SQL> select distinct deptno from dept  
where exists  
(select distinct deptno from emp where dept.deptno = emp.deptno)

    DEPTNO
----------
        30
        20
        10

3 rows selected.
SQL> select distinct deptno from dept  
minus  
select distinct deptno from emp

    DEPTNO
----------
        40

1 row selected.
SQL> select distinct  deptno from dept
where deptno not in  
(select distinct deptno from emp)

    DEPTNO
----------
        40

1 row selected.
SQL> select distinct deptno from dept  
where not exists  
(select distinct deptno from emp where dept.deptno = emp.deptno)

    DEPTNO
----------
        40

1 row selected.