Select语句-子查询
子查询
指嵌入在其他sql语句中的select语句,也叫嵌套查询
- 单行子查询:使用正常的关系表达符号 < > = !=
- 多行子查询:使用关键字 in
用在where条件中:用来辅助筛选条件
用在from条件中:用来作为临时表一起组合返回结果数据,解决复杂问题非常有效
-
使用all操作符:
- select ename,sal, deptno from emp where sal > all(select sal from emp where deptno = 30)
- 大于所有的为真
-
使用any操作符:
- select ename,sal, deptno from emp where sal > any(select sal from emp where deptno = 30)
- 大于任意的为真
-
多列子查询
查询返回多个列数据
(字段1,字段2) = (select 字段1,字段2 from ...)
注意字段1和字段2对比时顺序要一致