Total count greater than X

At times you need to find out how many values exist in a table with a total count greater than X. Perhaps this is for a report or debugging.

This handy query can provide just that information.

This example is searching a “user_table” and returns all first names were we have more than 1 value for the same first name.

SELECT DISTINCT(first_name) AS first_name, COUNT(first_name) AS count
FROM user_table GROUP BY first_name HAVING count > 1;