oracle12c intersect,Oracle数据库union, union all, intersect, minus使用

create table test3( id int primary key, name varchar2(50) not null, age number not null ); insert into test3 values(1,'张三',23); insert into test3 values(2,'李四',21); insert into test3 values(3,'王二',20); insert into test3 values(4,'郭经',20); insert into test3 values(5,'王伟',23); insert into test3 values(6,'Frado',24); insert into test3 values(7,'伍梅',23); insert into test3 values(8,'张伦',23); insert into test3 values(9,'郭飞',21); insert into test3 values(10,'刘鹏飞',22);

去重显示 select * from test3 where id < 4 union select * from test3 where id > 2 and id < 6;如果有交集, 会去重显示

不去重显示 select * from test3 where id < 4 union all select * from test3 where id > 2 and id < 6; 如果有交集, 不会去重显示

不排序 select * from test3 where id > 2 and id < 6 union all select * from test3 where id < 4;

union all不会排序

排序 select * from test3 where id > 2 and id < 6 union select * from test3 where id < 4;

union会排序显示

INTERSECT交集 只查询交集部分 select * from test3 where id > 2 and id < 6 intersect select * from test3 where id < 4;

只显示交集的数据

MINUS 查询存在数据 select * from test3 where id > 2 and id < 6 --3,4,5 MINUS select * from test3 where id<4; --1,2,3

如果A表中的数据存在B表中, 那么A表中的这条数据会被移除, 只显示A表中的结果, 不会显示B表中的结果;

73dfb951d1f0d8c339f5b0e67af37d30.png

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值