oracle按字段并集,oracle 交集和并集

select *from student1

union all

select *from student2

save_snippets.png

select *from student1

union all

select *from student2

查后后结果

62b38284a7004cbb5b7e8f346c94e03d.png

看到测试结果就明白了,union all对两个结果集进行并集操作,包括重复行,不进行排序。

如果去掉all 关键字,

[sql] view plaincopyprint?

select *from student1

union

select *from student2

save_snippets.png

select *from student1

union

select *from student2

528f20fc9c68a0fbfe1e4a6923d58d26.png

看到结果,得出的结论是:对两个结果集进行并集操作,不包括重复行,同时进行默认规则的排序

2.交集

[delphi] view plaincopyprint?

select *from student1

intersect

select *from student2

save_snippets.png

select *from student1

intersect

select *from student2

结果为:

62526008d14f9bc9e1cdd79d2051d8f8.png

是的,返回查询结果中相同的部分即是他们的交集

补充一下:minus 关键字

查询时候把表1放在前面,

[sql] view plaincopyprint?

select *from student1

minus

select *from student2

save_snippets.png

select *from student1

minus

select *from student2

结果为:

365c247446675b1f911eb31fb6a3f35d.png

查询时候把表2放在前面,

[sql] view plaincopyprint?

select *from student2

minus

select *from student1

save_snippets.png

select *from student2

minus

select *from student1

结果为:

0ea38323d1a90be3e046409fa54f5e73.png

使用 minus  返回在第一个查询结果中与第二个查询结果不相同的那部分行记录,即两个结果的差集

使用以上查询的结果集有两个最基本的规则:

(1)所有查询中的列数和列的顺序必须相同。

(2)数据类型必须兼容

oracle 交集和并集

标签:http   技术分享   images   返回   sel   phi   ati   static   默认

1428d0e076c3959ab11d28a39bc84fab.png

本条技术文章来源于互联网,如果无意侵犯您的权益请点击此处反馈版权投诉

本文系统来源:http://www.cnblogs.com/jiazuzhuzhu/p/6719339.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值