On 15 Feb 2016, at 8:58pm, James K. Lowden <jklowden at schemamania.org> wrote:
> Clemens Ladisch <clemens at ladisch.de> wrote: > >> I don't know why correlated subqueries cannot use values from the >> outer query in the ORDER BY or LIMIT clauses; > > ORDER BY is not part of SELECT! It's not a relational operator. > Per the SQL standard -- ORDER BY cannot appear in a subquery. It can > appear in only one place: as a kind of post-processor that determines > the order in which the rows are delivered to the client. And to build on that, if you cannot specify ORDER BY then you cannot expect LIMIT to do anything useful. Since you don't know which ones will be top in the list there's no point in picking just the top ones. It took me a long time to convince myself that SQL really was a language based on sets. And the elements of sets don't have any order. Simon.

