oracle exists minus,Oracle: minus | in | exists

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 21:04   5370   0

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.

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP