MySQL中 进行排序的方式:
Select * from 表名 [where 条件 order by 字段名(默认的是ASC升序排列)]
ASC是升序排列,DESC用来指定降序排列
Oracle中子查询:
Select * from 表名 where 条件 (select * from 表名 where 条件)
实例:
in: select * from emp where deptno in (select deptno from dept where loc = ‘DALLAS‘ or loc = ‘BOSTOM‘);
all: select * from emp where sal > all(select sal from emp where ename = ‘JAMES‘ or ename = ‘FORD‘);
any: select * from emp where sal > any(select sal from emp where ename = ‘JAMES‘ or ename = ‘FORD‘);
exists: select * from emp where exists (select sal from emp where ename = ‘JAMES‘ or ename = ‘FORD‘);
union操作用于计算两个结果集的并集,它在取并集时会自动去掉结果集的重复行。
select * from emp where sal <= 1600 union select * from emp where sal >= 1500;
intersect操作于计算两个结果集的交集
select * from emp where sal <= 1600 intersect select * from emp where sal >= 1500;
minus操作用于计算两个结果集的差集(只返回在第一个结果集中存在,但在第二个集中不存在的数据)
select * from emp where sal <= 1600 minus select * from emp where sal >= 1500;
其他方法: