Detect Duplicate Rows in a SQL Server Table

The customers table below has duplicate names inserted under different IDs:

id

name

email

1 John Doe john@teratrax.com
2 Mark Smith marks@teratrax.com
3 John Doe jdoe@company.com

 

The following SQL query returns a list of these rows and the number of times they occur (replace bold words to fit your table structure):

 

SELECT name, COUNT(*) AS counter
FROM customers
GROUP BY name
HAVING COUNT (*) > 1

 

Query result:

name counter
John Doe 2