3369
MySQLERRORNotableQuery ExecutionHIGH confidence

Non-aggregated column used with non-aggregate function in GROUP BY context

Production Risk

Medium — queries fail when ONLY_FULL_GROUP_BY is enforced.

How to reproduce
trigger — this will error
trigger — this will error
SELECT UPPER(name), COUNT(*) FROM t GROUP BY id;

expected output

ERROR 3369 (HY000): Non-aggregated column used in non-aggregate function.

Fix

Aggregate the column first

Aggregate the column first
SELECT UPPER(ANY_VALUE(name)), COUNT(*) FROM t GROUP BY id;

Why this works

ANY_VALUE reduces the group to a single value before passing it to UPPER().

What not to do

Sources
Official documentation ↗

MySQL 8.0 — 3369 ER_NON_AGGREGATED_COLUMN_WITH_NONAGG_FUNCTION

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All MySQL errors