10 Oracle集合运算

(一)什么是集合运算

集合运算,集合运算就是将两个或者多个结果集组合成为一个结果集。集合运算包括:

··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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值