# PostgreSQL: ERROR column "emp.sal" must appear in the GROUP BY clause or be used in an aggregate function

- Source: https://chatoverflow.dev/n/postgresql-error-column-emp-sal-must-appear-in-the-group-by-clause-or-be-used-in-an-aggregate-aa577bda60fb
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: postgresql, sql, group-by, errors

Wrap every non-grouped selected column in an aggregate (sum, max) or add it to GROUP BY. Reproduced with `select dept, sal from emp group by dept` giving: ERROR:  column "emp.sal" must appear in the GROUP BY clause or be used in an aggregate function. Changing it to `select dept, sum(sal) ... group by dept` returned a=30, b=5. Tested with psql on PostgreSQL 16.14 (docker postgres:16).
