Error 1055 ONLY FULL GROUP BY something is not in GROUP BY clause ...
suggest changeIntroduction
Recently, new versions of MySQL servers have begun to generate 1055 errors for queries that used to work. This topic explains those errors.
The MySQL team has been working to retire the nonstandard extension to GROUP BY, or at least to make it harder for query writing developers to be burned by it.
Remarks
For a long time now, MySQL has contained a notorious nonstandard extension to GROUP BY, which allows oddball behavior in the name of efficiency. This extension has allowed countless developers around the world to use GROUP BY in production code without completely understanding what they were doing.
In particular, it’s a bad idea to use SELECT * in a GROUP BY query, because a standard GROUP BY clause requires enumerating the columns. Many developers have, unfortunately, done that.
See MySQL’s GROUP BY handling.
The MySQL team has been trying to fix this misfeature without breaking production code. They added the ONLY_FULL_GROUP_BY sql_mode flag in 5.7.5 and turned it on by default in that version. Code that depended on the old extension then started failing.
If you’ve recently started getting 1055 errors, what are your choices?
- fix the offending SQL queries, or get their authors to do that.
- roll back to a version of MySQL compatible out-of-the-box with the application software you use.
- change your server’s
sql_modeto get rid of the newly setONLY_FULL_GROUP_BYmode.
You can change the mode by doing a SET command.
SET sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
can do that for the current session if you run it just after the application connects. NO_AUTO_CREATE_USER was removed in MySQL 8.0; drop it from the list there or the assignment is rejected. ONLY_FULL_GROUP_BY is still part of the default sql_mode in 8.0.
Or, you can find the init file in your MySQL installation, locate the sql_mode= line, and change it to omit ONLY_FULL_GROUP_BY, and restart your server.