Count Distinct Values
I want to select distinct values, and the count of the distinct values.
An example table would be:
I want my query to return:
| A |
| A |
| B |
I've tried permutations of count(distinct(field), field etc etc but I just end up with one row- when from looking at SELECT *, I can clearly see the query I'm wanting returned should have at least 100 rows.
| field | count(field) |
| A | 2 |
| B | 1 |
Edit: I know I can do this with php or two queries/stage table, but this really should be a 1 query thing.
Turns out I got it. I tried a sub-query but the number of rows didn't match up, so I fell back on my googlefu and found an answer.
SELECT DISTINCT table.field, Count(table.field) as Number
GROUP BY table.field
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)