The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →SQL rejects a plain column in a grouped query when that column could have multiple values within an output group. The database cannot know which value you mean. The right fix depends on what each output row should represent—not on adding every selected column to GROUP BY.
Why a column must appear in the GROUP BY clause
GROUP BY combines input rows that share the same grouping values. Each output expression must then have one well-defined value for every resulting group: it must be a grouping expression, an aggregate result, or, where the database supports and can establish it, a value functionally dependent on the grouping keys.
As an Amazon Associate I earn from qualifying purchases.
Consider this query:
SELECT department_id, employee_name, SUM(salary)
FROM employees
GROUP BY department_id;
The query asks for one row per department, and SUM(salary) can produce one salary total for each department. But a department can contain many employees, so employee_name has no single value for that department. The query has not specified which employee name to return.
Recommended Free Tools
PostgreSQL reports this as a grouping error, commonly with SQLSTATE 42803. Its documentation explains grouped queries and grouping expressions in Table Expressions. Exact error text varies by database and version.
#1 Best Overall
Choose a fix based on the row each result should represent
One row per department
If the question is “What is the salary total for each department?”, remove the employee-level name:
SELECT department_id, SUM(salary) AS total_salary
FROM employees
GROUP BY department_id;
Now both selected values describe the same grain: department.
One row per department and employee
If the question is instead about each department-and-employee combination, group by both columns:
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
SELECT department_id, employee_name, SUM(salary) AS total_salary
FROM employees
GROUP BY department_id, employee_name;
This is a different result. Adding employee_name splits each department into smaller groups, so the totals are no longer department-wide totals. Add a column to the grouping list only when that finer grain is what you intend.
Keep employee rows and show a department total
If you want each employee row to remain visible alongside the total for that employee’s department, use a window aggregate rather than collapsing rows with GROUP BY:
SELECT department_id,
employee_name,
SUM(salary) OVER (PARTITION BY department_id) AS department_total
FROM employees;
This is a general SQL pattern, but check your database’s documentation for supported syntax and features.
Rank #4
Calculate one total for the whole table
For a single overall total, select only the aggregate:
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Scan for outdated or missing drivers - takes under a minute3Clear out junk files and repair common Windows errorsSELECT SUM(salary) AS total_salary
FROM employees;
An aggregate query without GROUP BY returns an overall aggregate; pairing it with an arbitrary row-level field does not give that field a meaningful value.
Best Value
Why SQL databases can behave differently
PostgreSQL
When PostgreSQL raises the grouping error, inspect the selected expressions against the intended grouping keys. A plain value that varies within a group cannot identify itself from an aggregate such as SUM. Do not assume another database’s permissive behavior will be accepted or produce a meaningful result in PostgreSQL. See the PostgreSQL documentation on grouped queries.
MySQL 8.4
The MySQL 8.4 manual says ONLY_FULL_GROUP_BY is enabled by default. With that mode enabled, MySQL rejects nonaggregated selected or referenced expressions unless they are grouped, functionally dependent on grouping columns, or meet documented single-value conditions. If the mode is disabled, MySQL may choose any value from a group; an ORDER BY does not control which value is chosen. MySQL documents ANY_VALUE() for cases where an arbitrary value truly is acceptable, but that is not a general-purpose fix. Details are in the MySQL 8.4 GROUP BY handling documentation.
SQL Server
Microsoft’s SQL Server guidance says that columns used in a nonaggregate expression in the SELECT list must be included in the GROUP BY list. Its documentation also covers grouping extensions such as ROLLUP, CUBE, and grouping sets for subtotal and grouping-combination queries; those features are not needed to fix the basic ambiguity. See Microsoft Learn: GROUP BY (Transact-SQL).
A quick way to diagnose the error
- Write down the intended grain. Decide whether one output row should represent a department, an employee, a department-and-employee pair, or an original detail row.
- Check every selected expression. Each must be a grouping expression, an aggregate, or a value the database can prove is functionally dependent on the grouping keys.
- Choose the matching query shape. Use
GROUP BYto collapse rows into groups, a window aggregate to retain detail rows with a group-level calculation, or a plain aggregate without a row-level column for a whole-table total. - Verify the engine and version. If an exact fix depends on functional-dependency rules, aliases, or error wording, check the documentation for the database that actually runs the query.
A function such as MAX(employee_name) may make an expression aggregate syntactically, but it returns the maximum name under the database’s comparison rules—not necessarily the employee the question intends. Use an aggregate on a plain column only when that aggregate expresses the value you actually want.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




