Reputation: 2683
That headline does not fit but I cannot think of a better one.
I have the following table:
timestamp | userID | role
1438953971| 5 | 6
1438953982| 5 | 7
1438953985| 5 | 7
1438953990| 5 | 3
1438953999| 5 | 6
I would like to have a simple query for the number of roles used. So in this case it should be something like this:
role | used
6 | 2
7 | 2
3 | 1
I know that I can do it with PHP (not how yet), but I was "experimenting" with "count(distinct(role)) AS used" but that does not seem right.
Any hint appreciated.
Upvotes: 0
Views: 24
Reputation: 3801
You have to use GROUP BY:
SELECT ROLE, COUNT(*) FROM TABLE1 GROUP BY ROLE ORDER BY ROLE;
Upvotes: 2