ITPub博客

首页 > 数据库 > Oracle > Oracle中Union,Union All,Intersect,Minus的有什么区别

Oracle中Union,Union All,Intersect,Minus的有什么区别

Oracle 作者:athena721 时间:2011-02-19 14:21:40 0 删除 编辑

-- Union 是当存在重复记录行时,只取一行(也就是说重复记录行只显示一条),同时进行默认规则的排序;

-- Union all 是不管你有没有重复,都显示出来,不进行排序;

-- Intersect,对两个结果集进行交集操作,不包括重复行,同时进行默认规则的排序;

-- Minus,对两个结果集进行差操作,不包括重复行,同时进行默认规则的排序。

 

可以在最后一个结果集中指定Order by子句改变排序方式。

 

 

1.

select ntitle,ntid from newinfo where ntid='1010'

union

select ntitle,ntid from newinfo where ntid='154'

 

2.

select ntitle,ntid from newinfo where ntid='1010'

union all
select ntitle,ntid from newinfo where ntid='154'

 

3.

select ntitle,ntid from newinfo where ntid='1010'

Intersect

select ntitle,ntid from newinfo where ntid='154'

 

4.

select ntitle,ntid from newinfo where ntid='1010'

Minus

select ntitle,ntid from newinfo where ntid='154'

<!-- 正文结束 -->

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/23760110/viewspace-1117599/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 没有了~
下一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2010-04-20