集合运算
讲集合运算,实质上是讲集合运算的操作符
--查询部门号是10 和 20的员工信息
方法1
select * from emp where deptno in (10, 20);
方法2
select * from emp where deptno=10 or deptno=20;
方法3
select * from emp where deptno = 10
union
select * from emp where deptno = 20;
集合运算注意问题: 参与运算各个集合必须列数相同,且类型一致
采用第一个集合的表头作为最后的表头
必须在每一个集合后 使用相同的order by
使用括号
union UNION运算符返回两个集合去掉重复元素后的所有记录。
union all UNION ALL 返回两个集合的所有记录,包括重复的
intersect INTERSECT 运算符返回同时属于两个集合的记录
minus MINUS返回属于第一个集合,但不属于第二个集合的记录。