Remove duplicate rows from a large table in SQL Server

1152740 pts.
Tags:
SQL Server
For SQL Server, does anyone know the best way to remove duplicate rows from a large table? Here's what I have so far:
MyTable
-----------
RowID int not null identity(1,1) primary key,
Col1 varchar(20) not null,
Col2 varchar(2048) not null,
Col3 tinyint not null
Thanks!
1

Answer Wiki

Thanks. We'll let you know when a new response is added.

DELETE from search

where id not in (

select min (id) from search

group by url

having count (*) = 1

union

SELECT min (id) FROM search

group by url

having count (*) > 1

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • ToddN2000
    What determines a duplicate record, do all columns have to contain the same data or are you basing it on just a few columns? Are those columns listed the only one in the table?

    Show us what you have tried,
    135,465 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: