结果集的操作符
求并集:将两个结果集合并成一个结果集返回
union是求并集去重
union all是求并集不去重
select 1 as A from dual union select 1 as B from dual;
select 1 as A from dual union all select 1 as B from dual;
求交集:将两个结果集中公共部分作为结果集返回
select * from scott.emp where empno between 7369 and 7499 intersect select * from scott.emp where empno between 7499 and 7521;
求差集:定义操作符前面的结果集为A,后面的结果集为B,差集就是A结果集中减去A与B的交集,返回A中剩余的记录作为结果集。
select * from scott.emp where empno between 7369 and 7499 minus select * from scott.emp where empno between 7499 and 7521;
说明:
无论有多少个结果集,做运算的时候,相关结果集列的数量要一致。