How to find multiple/duplicate rows with the same value
June 27th, 2008
No comments
Just a short SQL script which will allow you to find the mutiple rows with the same values in the same table. I am not going to explain what the query does since its a very straight forward query
SQL:
-
SELECT [column_name]
-
FROM [tablename]
-
GROUP BY [column_name]
-
HAVING count(*)> 1
-
-- OR
-
-
SELECT * FROM [TableName] WHERE [ColumnName] IN (
-
SELECT [ColumnName] FROM (
-
SELECT count([ColumnName]) AS N, [ColumnName] FROM [TableName]
-
-- Where Clause If needed
-
GROUP BY [ColumnName]
-
)a
-
WHERE N> 1
-
)
There is a similar article which describes more techniques to follow for managing duplicate rows from a table .
http://support.microsoft.com/kb/139444
Sphere: Related Content