DBAtlas · Database operations atlas

1055: Expression not in GROUP BY (only_full_group_by)

MySQL

What does it mean?

A column that is neither in GROUP BY nor wrapped in an aggregate function was used in the SELECT list or in HAVING/ORDER BY. Because the ONLY_FULL_GROUP_BY SQL mode is enabled, MySQL rejects this nondeterministic expression.

Why does it happen?

The query selects a column other than the grouped columns directly, but that column may not have a single value per group. ONLY_FULL_GROUP_BY is enabled by default in MySQL 5.7+; queries relying on the old, lenient GROUP BY behavior raise this error.

How to fix it

Either add the column to the GROUP BY list or wrap it in an aggregate function (MAX(), MIN(), ANY_VALUE()). If you know the value is truly unique within the group, ANY_VALUE() deliberately suppresses the ambiguity. Disabling the mode (removing ONLY_FULL_GROUP_BY from sql_mode) instead of fixing the query brings back the risk of wrong results; avoid it.

Open in DBAtlas →

More from this engine