views:

643

answers:

3

Is there a simple way to retrieve a list of all unique values in a column, along with how many times that value appeared?

Example dataset:

A
A
A
B
B
C

... Would return:

A  |  3
B  |  2
C  |  1

Thanks!

+6  A: 

Use GROUP BY:

select value, count(*) from table group by value

Use HAVING to further reduce the results, e.g. only values that occur more than 3 times:

select value, count(*) from table group by value having count(*) > 3
cdonner
+3  A: 

select ID,count(*) FROM file GROUP BY ID

GoatRider
thank you thank you :)
Ian
A: 

if you were to display the count in php, how could this be done?