(一)什么是集合运算
集合运算,集合运算就是将两个或者多个结果集组合成为一个结果集。集合运算包括:
··UNION ALL(并集),返回各个查询的所有记录,包括重复记录。
··UNION(并集),返回各个查询的所有记录,不包括重复记录。
··INTERSECT(交集),返回两个查询共有的记录。
··MINUS(差集),返回第一个查询检索出的记录减去第二个查询检索出的记录之 后剩余的记录。
并集运算
UNIONALL 不去掉重复记录
select * from t_owners where id <= 7
union all
select * from t_owners where id >= 5
UNION 去掉重复记录
select * from t_owners where id<=7
union
select * from t_owners where id >= 5
交集运算
select * from t_owners where id <= 7
intersect
select * from t_owners where id >= 5
差集运算
select * from t_owners where id <= 7
minus
select * from t_owners where id >= 5
如果我们用 minus 运算符来实现分页,语句如下:
select rownum, t.* from t_account t where rownum <= 20
minus
select rownum, t.* from t_account t where rownum <= 10