多行子查询

学习多行子查询的时候发现一个有意思的点。

语法:安装oracle11g后,有一个默认的用户:scott

里面有两个表:emp(员工表)、dept(部门表)

EMP表:                                                                                                                                       DEPT表:

    

要求:查询EMP表中部门(dept.dname)不是SALES的员工。

思路:要的到要求必须在dept表中选取条件是dname<>SALSES

可以根据两个表都有的字段deptno进行关联:

select ename from emp  where deptno in

(select deptno from dept where dname<>SALSES)

即可满足要求,主要的思路是根据deptno作为两表桥梁通过在dept表中选取部门名称不为SALESE的条件来满足要求。

原文地址:https://www.cnblogs.com/shanpei/p/14600531.html