mysql count duplicates

SELECT name, food, COUNT(food) AS cnt
FROM table
GROUP BY name, food
HAVING (cnt > 1)

If you want the count of everything, not just the tuples with duplicates, then eliminate the HAVING line, as that’ll filter out anything that doesn’t have duplicates.

Leave a Comment