日期:2014-05-17  浏览次数:20996 次

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