Alexey Pechnikov <pechni...@mobigroup.ru> wrote: > 2010/10/26 Dan Kennedy <danielk1...@gmail.com> > >> The sorting happens after the grouping. And it is while processing >> the GROUP BY clause that SQLite is forced to select an arbitrary >> record from the user_record table. >> >> See here: >> >> http://www.sqlite.org/lang_select.html#resultset >> >> Third paragraph under the third bullet point. > > > No. See paragraph under bullet points: "The list of expressions between the > SELECT and FROM keywords".
I don't see how this is relevant. ORDER BY doesn't care about the expressions you list between SELECT and FROM. >Sort condition IS NOT the expression from the > third bullet point. These bullet points describe which rows are returned by the statement. Specifically, you start with "input data from the FROM clause", which is then "filtered by the WHERE clause", and finally, in the presence of GROUP BY, "each group of input dataset rows contributes a single row to the set of result rows". ORDER BY describes the order in which those result rows are returned: "if a SELECT statement does have an ORDER BY clause, then the list of expressions attached to the ORDER BY determine the order in which rows are returned". Note again that it works on result rows, not on input rows. In other words, ORDER BY is applied *after* GROUP BY. You cannot use ORDER BY clause to influence which single result row is chosen as a representative for its group of input rows. Igor Tandetnik _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users