Fix "column must appear in the GROUP BY clause"
By Sharon Ben-Moshe · June 25, 2026 · 4 min read
Sharon Ben-Moshe is the founder of sqlfmt, a browser-based SQL formatter and validator with misspelled-keyword suggestions across PostgreSQL, MySQL, SQLite, SQL Server, and BigQuery.
PostgreSQL's "column must appear in the GROUP BY clause" error (42803) fires when a SELECT column isn't grouped or aggregated. Three fixes, with examples.
Quick answer
PostgreSQL raises "column must appear in the GROUP BY clause or be used in an aggregate function" (error 42803) when a column in your SELECT list is neither named in GROUP BY nor wrapped in an aggregate like COUNT() or SUM(). Fix it by adding the column to GROUP BY, aggregating it, or replacing GROUP BY with a window function.