Skip to main content
The 2026 Annual Developer Survey is live— take the Survey today!

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Error related to only_full_group_by when executing a query in MySql

I have upgraded my system and have installed MySql 5.7.9 with php for a web application I am working on. I have a query that is dynamically created, and when run in older versions of MySQL it works fine. Since upgrading to 5.7 I get this error:

Expression #1 of SELECT list is not in GROUP BY clause and contains non-aggregated column 'support_desk.mod_users_groups.group_id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

Note the manual page for Mysql 5.7 on the topic of Server SQL Modes.

This is the query that is giving me trouble:

SELECT mod_users_groups.group_id AS 'value', 
       group_name AS 'text' 
FROM mod_users_groups
LEFT JOIN mod_users_data ON mod_users_groups.group_id = mod_users_data.group_id 
WHERE  mod_users_groups.active = 1 
  AND mod_users_groups.department_id = 1 
  AND mod_users_groups.manage_work_orders = 1 
  AND group_name != 'root' 
  AND group_name != 'superuser' 
GROUP BY group_name 
HAVING COUNT(`user_id`) > 0 
ORDER BY group_name

I don't understand only_full_group_by enough to figure out what I need to do to fix the query. Can I just turn off the only_full_group_by option, or is there something else I need to do?

Answer*

Draft saved
Draft discarded

Required fields are marked with *

Cancel
6
  • 103
    This is a work around, you better fix your query rather than silencing the warning Commented Jul 12, 2016 at 8:01
  • 3
    Updating the /etc/mysql/my.cnf (as seen below) is a more sustainable solution as the default settings tends to come back after restart. And for those that say you should fix the query, then that is not quite easy sometimes when you need a quick debugging query and do things like SELECT COUNT(*), t.* FROM my_table t GROUP BY col and you have 20-50 columns, do you want to spend that much time adding each column to the group by? Commented Jun 8, 2018 at 10:07
  • 6
    This "solution" is quite dangerous. You may activate modes you had disabled previously by blindly changing them instead of only removing the one settings flag in question. This may lead to unexpected behaviour and in worst case lead to wrong results or stop your app(s) from working entirely. Thus I consider this answer as wrong. Commented Sep 25, 2018 at 7:40
  • 3
    I made this persistent through refresh by figuring out my current sql_mode via SELECT @@sql_mode; and then adding the result from there to my.cnf: sql_mode=[list of modes from query, minus ONLY_FULL_GROUP_BY] Commented Mar 1, 2019 at 18:35
  • 3
    "Fixing your query" is difficult when all queries were done years ago by another person who is not in the company anymore ;) Commented Oct 26, 2020 at 17:06

lang-sql