在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. 剑指 offer set 25 求 1+2+...+n

    题目 要求不能使用乘除法, for, while, if else, switch, case 等关键字 思路 1. 循环已经命令禁止, 禁用 if, 意味着递归也不能使用. 但即便如此, 我们仍然要 ...

  2. 【NGUI】Unity3D UIGrid 排序、动态加载与销毁

    本帖最后由 Lucifer_H 于 2014-10-31 09:39 编辑 做 UIGrid 的动态加载是做游戏的装备列表时用到的,装备信息都是从后台发过来的,具体加载的代码如下: [C#] 纯文本查 ...

  3. std::ostringstream

    ostringstream是C++的一个字符集操作模板类,定义在sstream.h头文件中.ostringstream类通常用于执行C风格的串流的输出操作,格式化字符串,避免申请大量的缓冲区,替代sp ...

  4. 1455: 罗马游戏[左偏树or可并堆]

    1455: 罗马游戏 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1861  Solved: 798[Submit][Status][Discuss] ...

  5. Hibernate传递list参数的例子

    public Map<String, String> getAllFeedBack(Object[] obj){ Map<String, String> map = new H ...

  6. HDU 4605 Magic Ball Game(可持续化线段树,树状数组,离散化)

    Magic Ball Game Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  7. PHP之冒号、endif、endwhile、endfor 是什么鬼?f

    解释:其实这些都是PHP的语法,只不过不常用而已,这些都是PHP流程控制的替代语法. 冒号(:)相当于是 左大括号---->{ endif.endwhile.endfor.endforeach- ...

  8. Unpacking and repacking stock rom .img files

    http://forum.xda-developers.com/galaxy-s2/general/ref-unpacking-repacking-stock-rom-img-t1081239 OP ...

  9. Android 判断当前thread 是否是UI thread

    在Android 中判断当前的Thread是否是UI Thread 的方法: 1. if (Looper.myLooper() == Looper.getMainLooper()) { // Curr ...

  10. PCRE library

    wget http://nginx.org/download/nginx-1.15.6.tar.gz tar -xvf nginx-1.15.6.tar.gz ln -s nginx-1.15.6 n ...