SQL作用在关系上的union, intersect, minus 运算对应于数学集合论中的∪,∩, - 运算
并运算
查询部门号为20工资小于1000与部门号为10工资大于2000的员工信息:
select *
from emp
where deptno = 20 and sal < 1000
union
select *
from emp
where deptno = 10 and sal > 2000;
使用union all可以保留重复
交运算
查询工资大于2000且部门号为20的员工信息:
select *
from emp
where sal > 2000
intersect
select *
from emp
where deptno = 20;
差运算
查询工资>2000但是职位不是"MANAGER"的员工信息:
select *
from emp
where sal > 2000
minus
select *
from emp
where job = 'MANAGER';