3 ms·
I don't have MySQL handy, but this query doesn't even look like it should work. It groups by "activities.activity_type_id" but then includes "activity_types.*"
by default-kramer 9y ago
I don't have MySQL handy, but this query doesn't even look like it should work. It groups by "activities.activity_type_id" but then includes "activity_types.*" in the select list.
Unless MySQL is smart enough to do something like "implicit grouping" where if you group on the primary key it knows that all other columns of that table could also be included in the group... in which case I really should give MySQL another chance!
- Diederich 9y agoI believe MySQL does exactly this, but it's been a number of years since I worked with it in any depth.
- default-kramer 9y agoAh, I found it. It turns out if you include nonaggregated columns it will just pick one value from the group arbitrarily. https://dev.mysql.com/doc/refman/5.5/en/group-by-handling.html https://dev.mysql.com/doc/refman/5.5/en/group-by-handling.ht...