3
votes

I am trying to find a MySQL query that will find distinct values in a particular field, count the number of occurrences of that value.

example db

content_type    content_page    content_order
     23              25               1
     23              26               2
     24              25               2
     24              26               1
     24              28               1
     29              25               3

expected result

content_type    count
    23             2   
    24             3 
    29             1 

Thanks

2
you should accept the anwserRid Iculous

2 Answers

6
votes

Use the GROUP BY clause

SELECT content_type, COUNT(*)
FROM table_name
GROUP BY content_type

http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html

0
votes
SELECT content_type, COUNT(content_type) as count
FROM mytable
GROUP BY content_type