sql 子查询 嵌套SELECT 语句 嵌套SELECT 语句也叫子查询,一个 SELECT 语句的查询结果能够作为另一个语句的输入值
子查询不但能够出现在Where 子句中,也能够出现在from 子句中,作为一个临时表使用,也能够出现在select list 中,作为一个字段值来返回
1、单行子查询 :单行子查询是指子查询的返回结果只有一行数据
当主查询语句的条件语句中引用子查询结果时可用单行比较符号(=, >, =, 、< 、>= 、 select stName from Student where stId in(selectdistinct stId from score where teId=(select teId from teacher where teName='Rona')); 查询所有部门编号为 A 的资料: SELECT ename,job,sal FROM EMP WHERE deptno in ( SELECT deptno FROM dept WHERE dname LIKE 'A%'); 2)
多行子查询使用 ALL 操作符号例子:查询有一门以上的成绩高于 Kaka 的最高成绩的学生的名字: sql> select stName from Student where stId in(select distinct stId from score where score >all(select score from score where stId=(select stId from Student where stName= 'Kaka') )); 3)
多行子查询使用 ANY 操作符号例子:查询有一门以上的成绩高于 Kaka 的任何一门成绩的学生的名字: sql> select