in
举例:查询emp表中工资最高的员工的信息。
无关子查询:子查询在主查询之前执行一次,子查询的结果被用于主查询
select * from staff where sal in (select max(sal) from emp);
注意:in 后面的子查询返回的结果只能是和父查询的条件部分匹配,不能够是*(多个字段
Any
用法:用在非“=”的比较关系中,使用or串起来的比较从句
举例:找出员工中,只要比部门号为3的员工中的任何一个员工的工资高的其他部门的员工的姓名和工资。
select saff_name,staff_sal from staff where staff_sal>any(select staff_sal from staff where staff_dept=3) and staff_dept!=3;
some
用法:用于“=”关系的比较中,使用or串起来的比较从句
举例:找到和3部门员工的任何一个人工资相同的那些员工名称和工资
select staff_name,staff_sal from staff where staff_sal=some(select staff_sal from staff where dept_id=3) and dept_id!=3;
all
用法:使用and串起来的比较从句
举例:找到比部门号为2的员工的所有员工的工资都要高的员工
select ename,sal From emp Where sal>all(select sal from emp where deptno = 2) and dept !=2;