Skip to main content

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*

7
  • The first query is doing an implicit grouping by name. The second, wrote a similar way would be something like: SELECT name FROM users WHERE verified = '1' GROUP BY name ORDER BY COUNT(*) DESC LIMIT 0, 25 Commented Sep 12, 2014 at 3:56
  • I'm not sure what you're implying. With the query: SELECT name,type,language FROM synset WHERE verified = '1' GROUP BY name ORDER BY COUNT() DESC LIMIT 0, 25 The same error would occur. type isn't in Group By If I add type and language, the error disappears. Is this due to an upgrade to MySql maybe? SELECT name,type,language FROM synset WHERE verified = '1' GROUP BY name,type,language ORDER BY COUNT() DESC LIMIT 0, 25 will work fine. Commented Sep 12, 2014 at 4:13
  • terrible query time when adding all fields to the group by, obviously Commented Sep 12, 2014 at 4:16
  • 2
    Hi @James - any columns/expressions used in either the SELECT or ORDER BY clauses must be contained in the GROUP BY clause if they are not being aggregated (COUNT, SUM, etc). That is why you were getting the error - you were selecting the columns type, language, and code but they were not in the GROUP BY clause (as the accepted answer shows). If there is a setting in MySQL to automatically group, I would be extremely cautious of using that personally. Commented Sep 12, 2014 at 5:41
  • 3
    @JordanParker: "If there is a setting in MySQL to automatically group" - that is actually the default behaviour. James apparently enabled the ONLY_FULL_GROUP_BY option. Otherwise the statement would have just returned "random" results (MySQL doesn't call it random, they call it "indeterminate") percona.com/blog/2006/09/06/… Commented Sep 12, 2014 at 6:07