0

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

2
  • 1
    SELECT COUNT(DISTINCT user_id) FROM class_members WHERE class_id = 1; - done. Commented Jul 10, 2014 at 14:16
  • @FDL thank yuu for the answer it worked great! Commented Jul 10, 2014 at 14:19

1 Answer 1

4
SELECT class_id, COUNT(DISTINCT user_id) FROM mytable GROUP BY class_id 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.