SQL Server: Retrieve the duplicate value in a column

A common question, though filtering out suggests you want to ignore the duplicate ones? If so, listing unique values:

SELECT col 
FROM table
GROUP BY col 
HAVING (COUNT(col) =1 )

If you just want to filter so you are left with the duplicates

SELECT col, COUNT(col) AS dup_count
FROM table
GROUP BY col
HAVING (COUNT(col) > 1) 

Used www.mximize.com/how-to-find-duplicate-values-in-a-table- as a base in 2009; website content has now gone (2014).

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)