在Oracle中提供了三种类型的集合操作: 并(UNION)、交(INTERSECT)、差(MINUS)

Union:对两个结果集进行并集操作,不包括重复行,同时进行默认规则的排序;

Union All:对两个结果集进行并集操作,包括重复行,不进行排序;

Intersect:对两个结果集进行交集操作,不包括重复行,同时进行默认规则的排序;

Minus:对两个结果集进行差操作,不包括重复行,同时进行默认规则的排序。

可以在最后一个结果集中指定Order by子句改变排序方式。

--测试表A中的记录见下
select * from TestA;

--对两个结果集进行并集操作,不包括重复行
select * from TestA where id<3 union select * from TestA where id<6;

--对两个结果集进行并集操作,包括重复行行
select * from TestA where id<3 union all select * from TestA where id<6;

--对两个结果集进行交集操作,不包括重复行
select * from TestA where id<3 intersect select * from TestA where id<6;

--对两个结果集进行差操作(前面的结果集减去后面的),不包括重复行
select * from TestA where id<6 minus select * from TestA where id<3;

--对三个结果集进行取并集操作(取到的结果是从左到右依次的值不进行排序)在最后进行order by 操作
select * from (select * from TestA where id>5 union all select * from TestA where id<3 union all select * from TestA where id<2) order by id asc;

select * from (select * from TestA where id>5 union all select * from TestA where id<3 union all select * from TestA where id<2) order by id desc;

Oracle Union Union All 对查询结果集操作的更多相关文章

  1. Oracle 中 union 和union all 的简单使用说明

    1.刚刚工作不久,经常接触oracle,但是对oracle很多东西都不是很熟.今天我们来了解一下union和union all的简单使用说明.Union(union all): 指令的目的是将两个 S ...

  2. Oracle中Union与Union All的区别(适用多个数据库)

    Oracle中Union与Union All的区别(适用多个数据库) 如果我们需要将两个select语句的结果作为一个整体显示出来,我们就需要用到union或者union all关键字.union(或 ...

  3. Oracle之Union与Union all的区别

    如果我们需要将两个select语句的结果作为一个整体显示出来,我们就需要用到union或者union all关键字.union(或称为联合)的作用是将多个结果合并在一起显示出来. union和unio ...

  4. Oracle 中 union与union all

    如果我们需要将两个select语句的结果作为一个整体显示出来,我们就需要用到union或者union all关键字. union(或称为联合)的作用是将多个结果合并在一起显示出来. union和uni ...

  5. Oracle中 union 和 union all 的区别

    如果我们需要将两个select语句的结果作为一个整体显示出来,我们就需要用到union或者union all关键字. union(或称为联合)的作用是将多个结果合并在一起显示出来. union和uni ...

  6. UNION ALL合表查询

    有时候需要连表查询数据,可以使用union all来做合表. 语法: SELECT column_name FROM table1UNION ALLSELECT column_name FROM ta ...

  7. ORACLE中union/union all/Intersect/Minus用法

    Union,对两个结果集进行并集操作,不包括重复行,同时进行默认规则的排序: Union All,对两个结果集进行并集操作,包括重复行,不进行排序: Intersect,对两个结果集进行交集操作,不包 ...

  8. oracle中union和union all区别与性能分析

    [ 概要 ] 经常写sql的同学可能会用到union和union all这两个关键词, 可能你知道使用它们可以将两个查询的结果集进行合并, 那么二者有什么区别呢? 下面我们就简单的分析下. [ 比较 ...

  9. MySQL多表查询合并结果union all,内连接查询

    MySQL多表查询合并结果和内连接查询 1.使用union和union all合并两个查询结果:select 字段名 from tablename1 union select 字段名 from tab ...

随机推荐

  1. js中的问题(this)(遍历对象中的属性)

    for (var i in this) { if (this[i] == null) this[i] = "";//属性如果为null,则默认为"";      ...

  2. [转]Loadrunner经典面试题

    http://www.mianwww.com/html/category/it-interview/loadrunner/  史上最全 在LoadRunner中为什么要设置思考时间和pacing 答: ...

  3. 【Debian】时间设置

    http://blog.linuxphp.org/archives/567/ http://www.dedecms.com/knowledge/servers/linux-bsd/2012/0819/ ...

  4. MyBitis(iBitis)系列随笔之六:mybitis与spring集成

    目前Spring官方还没有出整合Mybatis的特性,但是mybitis比较给力,开发了一个mybatis-spring插件,达到与Spring的完美整合目的. 在与Spring集成前,一方面我们需要 ...

  5. 谈谈Jquery ajax中success和complete有哪些不同点

    记录下,以备将来有需时用 http://www.jb51.net/article/75206.htm

  6. iOS 创建本地私有库 保存功能代码

    创建本地私有库 >>> cd /Users/cxx/Desktop/Mange_JJH/Lib >>> pod lib create TZTools >> ...

  7. 部署全局ajax处理

    $.ajaxSetup({ beforeSend:function(){ $('.loading').show(); }, complete:function(){ $('.loading').fad ...

  8. import cx_Oracle报错,提示importError: DLL load failed: 不是有效的Win32程序。

    问题说明1:WIN32,python是2.7版本,本地oracle client是32位的.import cx_Oracle报错,提示importError: DLL load failed: 该模块 ...

  9. hdu1059(多重背包优化)

    使用一种二进制的优化, 可以完美的解决这题,<背包九讲>中说的非常好 但是还有一种线性复杂的算法. 应该算是该题很巧妙的解法 ;i++) { ;l--) { ) continue; ;k& ...

  10. JS如何获取url查询字符串的键和值?

    /** * 根据url查询字符串里的键名获取其值 */function getSearchString(key, search) { // 获取URL中?之后的字符 var str = search; ...