Home Products Support Sales Corporate
Products
Performance Monitor
Database Compare
Database Manager
Job Scheduler






Home > Articles > SQL Server Development & T-SQL > Detect duplicate rows in a SQL Server table

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

 

 

 



Privacy Statement License Agreement Articles Site Map         Copyright © 2002-2008 Teratrax Inc. All rights reserved.