3 ms·
Shame they appear to have confused how GROUP BY works. They're correct that - SELECT users.*, count(photos.id) FROM users LEFT OUTER JOIN photos ON users.id
by mst 17y ago
Shame they appear to have confused how GROUP BY works. They're correct that -
SELECT users.*, count(photos.id)
FROM users
LEFT OUTER JOIN photos
ON users.id = photos.user_id
GROUP BY photos.user_id
won't do what they want. In fact, it isn't even a valid query outside of MySQL that I can think of.
What -will- do the right thing is:
SELECT users.id, users.name, count(photos.id)
FROM users
LEFT OUTER JOIN photos
ON users.id = photos.user_id
GROUP BY users.id, users.name
(which in the conceptually similar perl thing I'm working on at the moment you'd represent just by asking for a set of user objects with $user->photos->count eager loaded, but anyway ...)