Friday, June 29, 2012

Delete duplicate rows from a table with an identity column

T-SQL statement to delete duplicate rows from a table with an identtity column. When several records have equal data in other columns and only one record should be kept.

DELETE FROM dbo.TableA
WHERE Id NOT IN
(
SELECT MIN(Id)
FROM dbo.TableA
GROUP BY Column1, Column2 -- combination of columns that gives duplicates
)

2 comments:

Zalak Thakkar said...

Want to Display unique records from view

Zalak Thakkar said...

I m using visual studio light switch 2013