Oracle中Union与Union All的区别
Oracle中Union与Union All的区别
如果我们需要将两个select语句的结果作为一个整体显示出来,我们就需要用到union或者union all关键字。union(或称为联合)的作用是将多个结果合并在一起显示出来。
union和union all的区别是,union会自动压缩多个结果集合中的重复结果,而union all则将所有的结果全部显示出来,不管是不是重复。
Union:对两个结果集进行并集操作,不包括重复行,同时进行默认规则的排序;
Union All:对两个结果集进行并集操作,包括重复行,不进行排序;
Intersect:对两个结果集进行交集操作,不包括重复行,同时进行默认规则的排序;
Minus:对两个结果集进行差操作,不包括重复行,同时进行默认规则的排序。
可以在最后一个结果集中指定Order by子句改变排序方式。
例如:
<div style="padding: 1px 0px 0px; background-color: #e7e5dc; width: 893.9666748046875px; overflow: auto; margin: 18px 0px !important;" class="dp-highlighter"><div style="margin: 0px; padding: 0px 0px 0px 45px;" class="bar"><div style="margin: 0px; padding: 3px 8px 10px 10px; font-size: 9px; color: silver; background-color: #f8f8f8; border-left-width: 3px; border-left-style: solid; border-left-color: #6ce26c;" class="tools">Java代码 http://weich-javadeveloper.javaeye.com/images/icon_copy.gif
页:
[1]