On 9/14/14, Lea Verou <l...@verou.me> wrote:
> Per the 3.7.11 changelog [1], queries of the form SELECT max(x), y FROM
> table return the value of y from the same row that contains the maximum x
> value. However, this:

Hello!  I don't think this is a bug.  The documentation for the SELECT
statement at "http://sqlite.org/lang_select.html"; says:

> If the SELECT statement is an aggregate query without a GROUP BY clause, then 
> [...] Each non-aggregate expression in the result-set is evaluated once for 
> an arbitrarily selected row of the dataset. The same arbitrarily selected row 
> is used for each non-aggregate expression.

This applies to your query, so y will return the value y from any row.
If it happens to return the value where x is maximal, that is an
accident, and might depend on what indexes you have or how sqlite
chooses to optimize your query.  You have no reason to trust sqlite to
choose any particular column.

If you would definitely like to get the value of y from the row where
x is maximal, I recommend a query like this:

  SELECT x, y FROM sometable ORDER BY x DESC LIMIT 1;

-- Ambrus
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to