Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 deleting duplicates

Author  Topic 

ben_53
Yak Posting Veteran

67 Posts

Posted - 2011-07-28 : 13:48:29
Hi experts,

I want to delete the duplicate rows in my table. which has 5 columns.
col1 is identity column.

I am using the query:

DELETE FROM my_table
WHERE col1 NOT IN
( SELECT MIN (col1)
FROM my_table
GROUP BY col2,col3,col4,col5)

It deleted many duplicates but not all. Kindly help.
Thanks

ben_53
Yak Posting Veteran

67 Posts

Posted - 2011-07-28 : 14:21:33
I used the query that solved the business logic:



With cte As
(
SELECT ROW_NUMBER() OVER (PARTITION BY Col1, Col2, Col3 ORDER BY (SELECT 0)) RN
FROM MyTable
)
DELETE FROM cte WHERE RN<> 1
Go to Top of Page
   

- Advertisement -