Hi.
We know that subqueries can be placed in the WHERE, HAVING, FROM and SELECT clauses of a query (under certain conditions, especially in SELECT). One can also use subqueries in the START WITH clause of a hierarchical query. However, I have never come across a statement in any book or documentation that a subquery may appear in the ORDER BY clause.
But a query
select *
from emp e
order by (select empno from emp where e.mgr = empno);
(on a standard emp table) works. Of course, this is a specific case, because it is a correlated query and returns exactly one row - the boss of a given employee. But why does it even work? Is it mentioned somewhere in the documentation? Are there any other surprising places where subqueries might appear?
Thanks for help.