ORACLE union all 与 union 的区别

来源:互联网 发布:网络教育第二本科证书 编辑:程序博客网 时间:2024/05/18 02:41

Union 与 Union ALL 的作用都是合并 SELECT 的查询结果集,那么它们有什么不同呢?
Union 将查询到的结果集合并后进行重查,将其中相同的行去除。缺点:效率低;
而Union ALL 则只是合并查询的结果集,并不重新查询,效率高,但是可能会出现冗余数据。

 

下边会出现2条数据

select rowid,t.* from tabletest  t where t.id='10999201405201303066240000115487'
union all
select rowid,t.* from tabletest  t where t.id='10999201405201303066240000115487'

 

下边出现1条数据

select rowid,t.* from tabletest  t where t.id='10999201405201303066240000115487'
union
select rowid,t.* from tabletest  t where t.id='10999201405201303066240000115487'

 

0 0