How to Resolve MySQL Error Code 1055
Robert Cooper
Robert Cooper Senior Engineer at Basedash
· January 31, 2025
Robert Cooper
Robert Cooper Senior Engineer at Basedash
· January 31, 2025
MySQL Error Code 1055 means a query violates the ONLY_FULL_GROUP_BY SQL mode, typically occurring in GROUP BY queries where non-aggregated columns are not functionally dependent on the grouped columns. This error ensures result consistency, avoiding ambiguous query results.
Error 1055 is triggered when a SELECT statement includes a GROUP BY clause, but the SELECT list contains columns that are not in the GROUP BY clause and are not enclosed in an aggregate function like COUNT(), SUM(), MAX(), etc.
This error is closely associated with the ONLY_FULL_GROUP_BY SQL mode in MySQL. When enabled, it restricts the SELECT statements to have only those columns in the SELECT list that are functionally dependent on the GROUP BY columns or are used in aggregate functions.
First, review the query that caused the error. Identify columns in the SELECT list that are neither part of the GROUP BY clause nor aggregated.
Before correction:
SELECT name, COUNT(*) FROM employees GROUP BY department_id;
After correction:
SELECT department_id, COUNT(*) FROM employees GROUP BY department_id;
Or using an aggregate function:
SELECT MAX(name), COUNT(*) FROM employees GROUP BY department_id;
As a last resort, if the query logic requires columns that cannot be included in the GROUP BY clause or aggregated, consider disabling the ONLY_FULL_GROUP_BY mode. However, this is generally not recommended as it can lead to unpredictable results.
SET sql_mode = (SELECT REPLACE(@@sql_mode, 'ONLY_FULL_GROUP_BY', ''));
In conclusion, MySQL Error Code 1055 is a safeguard against ambiguous or potentially incorrect query results in GROUP BY queries. Understanding the role of the ONLY_FULL_GROUP_BY mode and appropriately structuring queries can effectively resolve this error.
Written by
Senior Engineer at Basedash
Robert Cooper is a senior engineer at Basedash who builds full-stack product systems across SQL data infrastructure, APIs, and frontend architecture. His work focuses on application performance, developer velocity, and reliable self-hosted workflows that make data operations easier for teams at scale.
Basedash lets you build charts, dashboards, and reports in seconds using all your data.