oracle中union和union all
2020-06-06 07:14
344 查看
union: 对两个结果集进行并集操作, 不包括重复行,相当于distinct, 同时进行默认规则的排序
union all: 对两个结果集进行并集操作, 包括重复行, 即所有的结果全部显示, 不管是不是重复
实际证明
1、准备对应的数据
create table demo( id int primary key not null, dname varchar2(50) not null, age varchar2(50) not null ); insert into demo values(1,'t1','1'); insert into demo values(2,'t2','2'); insert into demo values(3,'t3','3'); insert into demo values(4,'t4','4'); insert into demo values(5,'t5','5');
2、union和union all进行比较
select * from demo d where d.id > 1 union select * from demo d where d.id > 4; select * from demo d where d.id > 1 union all select * from demo d where d.id > 4;
union的执行结果
union all的执行结果
总结
union: 对两个结果集进行并集操作, 不包括重复行,相当于distinct, 同时进行默认规则的排序,效率不高,因为他对查询的结果集进行了排序和去重
union all: 对两个结果集进行并集操作, 包括重复行, 即所有的结果全部显示, 不管是不是重复,效率高
相关文章推荐
- Oracle sql union all
- Oracle 中 union 和union all 的简单使用说明
- oracle union union all 区别
- Oracle中的Union、Union All、Intersect、Minus
- Oracle UNION ALL/UNION/INTERSECT/MINUS
- Oracle集合运算符,合集:Union/Union All ,交集:Intersect,差集:Minus
- Oracle UNION ALL替换UNION
- ORACLE的UNION和UNION ALL 的用法1
- Oracle union all和order by一起使用
- Oracle UNION ALL
- oracle union all
- Oracle union all和order by一起使用
- Oracle的Union、Union_All、Intersect、Minus用法---小笔记
- oracle union all和order by一起使用
- Oracle Union Union All 对查询结果集操作
- oracle union all和order by一起使用
- oracle union union all intersect minus的含义及区别
- 9-oracle_union和union all
- oracle中的union和union all
- ORACLE union all 与 union 的区别