Reputation: 121
I have a mysql statement as follows:
SELECT * FROM class_members WHERE class_id = 1;
Which returns the following result:
class_id | user_id
1 | 2
1 | 1
1 | 3
1 | 5
I want to count all the unique user_ids per class.
Can anyone help?
Thank you
Upvotes: 0
Views: 29
Reputation: 425431
SELECT class_id, COUNT(DISTINCT user_id)
FROM mytable
GROUP BY
class_id
Upvotes: 4