SQLite Forum

Invalid group by usage?
Login
This is documented. SQLite allows nonaggregated columns in aggregate queries.

If there is exactly one aggregate function in the query, and that function is MIN() or MAX(), then the column will be taken from one of the rows that exhibits the MIN or MAX value (if a GROUP BY is added, this applies to the groups' MIN or MAX value respectively).

SELECT max(a),b FROM T;

is equivalent to

SELECT a,b FROM T where a = (SELECT max(a) FROM T) LIMIT 1;

but requires only 1 traversal of the table instead of an average 1.5