1435
MySQLERRORNotableQueryHIGH confidence
Non-grouping field used in HAVING clause
Production Risk
Low — query will not execute; fix the query logic.
What this means
ER_NON_GROUPING_FIELD_USED (1435, SQLSTATE HY000) is raised when a column referenced in a HAVING clause is not part of a GROUP BY expression or an aggregate function.
Why it happens
- 1Referencing a non-aggregated column in HAVING that is not in GROUP BY
- 2sql_mode=ONLY_FULL_GROUP_BY is enabled (default in MySQL 5.7.5+)
How to reproduce
trigger — this will error
trigger — this will error
SELECT dept, COUNT(*) FROM employees GROUP BY dept HAVING salary > 50000; -- salary not in GROUP BY or aggregate
expected output
ERROR 1435 (HY000): Non-grouping field 'salary' is used in HAVING clause
Fix
Move the filter to WHERE or use an aggregate
Move the filter to WHERE or use an aggregate
-- Use WHERE for row-level filtering: SELECT dept, COUNT(*) FROM employees WHERE salary > 50000 GROUP BY dept; -- Or aggregate in HAVING: SELECT dept, COUNT(*) FROM employees GROUP BY dept HAVING MAX(salary) > 50000;
Why this works
WHERE filters rows before grouping; HAVING should only reference grouped or aggregated columns.
Version notes
MySQL 5.7.5+
ONLY_FULL_GROUP_BY is enabled by default, enforcing this restriction.
Sources
Official documentation ↗
MySQL 8.0 — 1435 ER_NON_GROUPING_FIELD_USED
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev