zsychanpin


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

  • UNION:将多个查询的结果组合到一个查询结果之中,并去掉反复值
  • UNION ALL:将多个查询结果组合到一个查询结果中。可是包括反复值
  • INTERSECT:返回多个查询结果同样的部分
  • MINUS:返回两个查询结果的差集


首先,创建还有一个表 emp10

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

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


select * from emp10;


select * from emp;


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

select * from emp10
union
select * from emp


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

select * from emp10
union all
select * from emp


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

select * from emp10
intersect 
select * from emp;


minus 取差集

select * from emp
minus
select * from emp10;


换个写法

select * from emp10
minus
select * from emp;

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




分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-29
猜你喜欢
  • 2022-02-23
  • 2021-07-02
  • 2021-07-07
  • 2022-12-23
  • 2021-10-20
  • 2021-11-29
相关资源
相似解决方案