Oracle结果集操作

来源:互联网 发布:关于喝酒的网络歌曲 编辑:程序博客网 时间:2024/05/24 07:34
结果集:通俗的讲,其实就是你通过select语句查找到的数据行的集合
我们可以对结果集进行各种操作,但这个是有前提的,前提是你的结果集查询的字段以及查询的列数是一样的
现有一张学生表用于本节演示,结构以及数据如下:

对结果集的操作可以有如下几种:
union union all minus intersect
union:联合两个结果集,但是会去掉重复的数据
例如:
select a.id,a.namefrom student awhere a.id <3UNIONselect b.id,b.namefrom student bwhere b.id <4
执行结果:

union all:联合两个结果集,但是会保留 重复数据
比如:
select a.id,a.namefrom student awhere a.id <3UNION ALLselect b.id,b.namefrom student bwhere b.id <4
执行结果:

minus:把两个结果集中相同的数据去掉,返回留下的数据
比如:
select a.id,a.namefrom student awhere a.id <3MINUSselect b.id,b.namefrom student bwhere b.id <4
执行结果:

intersect:取交集,保留结果集相同的部分
select a.id,a.namefrom student awhere a.id <3INTERSECTselect b.id,b.namefrom student bwhere b.id <4
执行结果:

原创粉丝点击