Question:
Can order by
clause obtain column names when we specify asterisk *
instead of column names in a select
query?
The following code works, so the answer seems to be "yes":
select * from dual
order by dummy
The following code does not work, so the answer seems to be "no":
select * from dual
union all
select * from dual
order by dummy
Is this behaviour documented?
In the SQL Reference Manual, under "Sorting Query Results":
So in your case
select * from dual
union all
select * from dual
order by 1
works as expected, as does
select dummy from dual
union all
select dummy from dual
order by dummy