Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

ORDER BY columns in a UNION

sperkmandlDec 6 2010 — edited Dec 6 2010
Hi all, I have a pair of statements connected by a UNION, where I need to sort the final result according to columns not appearing in any column list:

SELECT REF(d) FROM DOCUMENT_TABLE d
WHERE d.header$.parentKey = ?
UNION
SELECT REF(d) FROM DOCUMENT_TABLE d, CROSS_TABLE k
WHERE k.doc = d.key$ AND k.folder = ?
ORDER BY d.header$.name

this fails saying that d.header$.name is an invalid identifier (ORA-904), like being out of scope.
Both union branches succeed when run alone (select + order by).
How can I sort by colums without having them to be returned ?
In all examples I found columns are also retrieved and referenced by either alias or by position.
Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 3 2011
Added on Dec 6 2010
9 comments
1,194 views