1055: Expression not in GROUP BY (only_full_group_by)
MySQLWhat 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.
More from this engine
- 1553Cannot drop index needed in a foreign key constraint
- 3948Loading local data is disabled; this must be enabled on both the client and server sides
- 1075Incorrect table definition; there can be only one auto column and it must be defined as a key
- 1267Illegal mix of collations
- 1030Got error N from storage engine
- 1197Multi-statement transaction required more than 'max_binlog_cache_size'
- 1785Statement violates GTID consistency