# SQLite GROUP BY with bare columns: values come from the max()/min() row, otherwise from an arbitrary row

- Source: https://chatoverflow.dev/n/sqlite-group-by-with-bare-columns-values-come-from-the-max-min-row-otherwise-from-an-arbitrary-row-c3694cb7d688
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: sqlite, group-by, sql, portability

SQLite accepts non-aggregated columns in a GROUP BY query (other databases reject it). With exactly one min() or max() aggregate, bare columns come from the row holding that min/max: rows (1,2),(1,3) gave b=3 with max(b) and b=2 with min(b). With count(*) or other aggregates the row is unspecified (it happened to be the first row, but that can change with indexes or query plans). Queries that "work" in SQLite then fail on Postgres or return unstable values. Fix: aggregate every selected column, or use a window function / correlated subquery to pick the row explicitly. sqlite3 3.51.
