On Mon, 4 Feb 2019 18:55:33 +0100 Gerlando Falauto <gerlando.fala...@gmail.com> wrote:
> I remember reading ORDER BY is only allowed in > the outer query As Keith said, SQLite allows ORDER BY in subqueries. The SQL standard does not. Logically, ORDER BY makes sense only for the outer query. An SQL SELECT statement decribes a set of results, possibly presented in a particular order. An "internal ORDER BY" describes neither selection criteria nor presentation order. Technically, ORDER BY takes a tabular result as input and produces a cursor as output. It need not sort the results; all that's required is that the cursor return successive rows in the prescribed order. SQLite extends ORDER BY with LIMIT. Because the combination affects more than just the order, it can be useful to use ORDER BY in a subquery. Now that window functions provide a (more convenient) standard way to produce row numbers, LIMIT is a bit of anachronism but, for reasons of backwards compatibility, is unlikely to be removed. --jkl _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users