在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. redhat6.2 clang编译环境搭建(采用源码包编译安装)

    1. About clang++ office site:http://clang.llvm.org/ A major focus of our work on clang is to make it ...

  2. linux下面bin,sbin不理解的查阅

    在一下的文件中得到答案, 突然想想自己有点傻,自己有代码,为什么不自己查看一下代码呢 http://blog.csdn.net/ithomer/article/details/9839957

  3. php使用json_encode后出现中文乱码的解决方法

    <?php header("content-type:text/html;charset=utf-8"); $data = array('a'=>123,'b'=> ...

  4. js 版本号

    在web项目开发过程中,我们经常会引用css.js文件,更新文件后常出现缓存问题(明明更改了代码,在浏览器上访问的时候却没有发生变化),这种情况我们通常采用以下两种解决方案: 1.手动清除浏览器缓存 ...

  5. 【cb2】安装终端

    虽然xterm轻量,但用起来不爽. sudo apt-get install terminator 其它安装 sudo apt-get install spyder sudo apt-get inst ...

  6. MFC中给控件添加变量,DoDataExchange中

    DoDataExchange函数其实是一项数据动态绑定技术.比如你在写动态按钮过程中须对按钮添加变量时,怎么添加?控件类已经写好了,其变量是已经固定的.你要添加新的变量就要用到DoDataExchan ...

  7. 指针*pbuffer和getchar 读取字符串

    在C语言入门教材里看到这一段代码,没看懂是什么意思.char buffer[10];char *pbuffer = buffer;while( (*pbuffer++ = getchar() )!= ...

  8. Js 的几种去重(一维)

    写的几种数组去重方法: 第一种: [利用排序方法,然后比较当前元素与下一个元素是否相等] function repeat1(arr) { var length = arr.length; var re ...

  9. THINKPHP5判断当前浏览器请求方式

    作用 代码 是否为 GET 请求 if (Request::instance()->isGet()) 是否为 POST 请求 if (Request::instance()->isPost ...

  10. ios开发之 -- x-code删除描述文件

    描述文件所在的目录是:~/Library/MobileDevice/Provisioning\ Profiles/ 进入这个目录,删除所有描述文件.