Oracle集合操作

刺骨的言语ヽ痛彻心扉 2022-08-03 13:51 532阅读 0赞

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

  • UNION:将多个查询的结果组合到一个查询结果之中,并去掉重复值

  • UNION ALL:将多个查询结果组合到一个查询结果中,但是包含重复值

  • INTERSECT:返回多个查询结果相同的部分

  • MINUS:返回两个查询结果的差集

首先,创建另一个表 emp10

  1. -- 创建重复数据表 emp10
  2. create table emp10 as (select * from emp where deptno = 10);

查看emp10 和 emp 表数据项,emp10 共有3条记录,emp表有14条记录。

  1. select * from emp10;

SouthEast

  1. select * from emp;

SouthEast 1

union 多个结果并集,并去掉重复值

  1. select * from emp10
  2. union
  3. select * from emp

SouthEast 2

union all 取并集且不去除重复项

  1. select * from emp10
  2. union all
  3. select * from emp

SouthEast 3

intersect 返回多个查询结果相同的部分

  1. select * from emp10
  2. intersect
  3. select * from emp;

SouthEast 4

minus 取差集

  1. select * from emp
  2. minus
  3. select * from emp10;

SouthEast 5

换个写法

  1. select * from emp10
  2. minus
  3. select * from emp;

SouthEast 6

通过换写法之后的查询结果,可以看出,minus取的是第一个集合中有但第二个集合中没有的记录。

发表评论

表情:
评论列表 (有 0 条评论,532人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Git操作集合

    Git操作集合 以下所述xxx为操作文件或分支名 1. 修改本地代码并提交到远程仓库 git add xxx git commit -m ‘x

    相关 ORACLE 集合操作

    ORACLE语句中的集合关键字: union和union all的区别是,union会自动压缩多个结果集合中的重复结果,而union all则将所有的结果全部显示出来,不管

    相关 Oracle集合查询

    1、并集运算:union      注意:union:二个集合中,如果都有相同的,取其一;                union all:二个集合中,如果都有相同的,都