I have a sql-query to get the number of users of each group and sort all groups by them. But unfortunately, sql thinks that user_count is 1 when in fact it must be 0. If the number of users is greater than 0, it takes the correct value.
Here is my sql query:
SELECT G.id, COUNT(*) user_count
FROM groups G LEFT JOIN
users U
ON G.id = U.group_id
GROUP BY G.id
ORDER BY user_count
In groups table i have group ids in the field id and in users table i have users with their group ids in the field group_id
I'm not so good in SQL, so maybe i'm making some very stupid mistakes. Thank you in advance if you can help.