当前位置: 代码迷 >> Oracle开发 >> union后面的order by 对什么结果排序,该怎么解决
  详细解决方案

union后面的order by 对什么结果排序,该怎么解决

热度:121   发布时间:2016-04-24 07:56:27.0
union后面的order by 对什么结果排序
我的SQL语句是:
select   .......     (1)
union
select   .......     (2)  
order   by   .....

想问一下,order   by后面的排序条件是对select(2)的结果排序还是对整个union
出来的结果进行排序?
我的目的是要对整个union出来的结果进行排序
这样能实现不?


------解决方案--------------------
SQL> select 2 a from dual
2 union all select 1 a from dual
3 union all select 3 a from dual
4 union all select 5 a from dual;

A
----------
2
1
3
5

SQL>
SQL> select 2 a from dual
2 union all select 1 a from dual
3 union all select 3 a from dual
4 union all select 5 a from dual order by a;

A
----------
1
2
3
5

SQL
  相关解决方案