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
 delete duplicates

Author  Topic 

jgrant
Yak Posting Veteran

69 Posts

Posted - 2007-03-20 : 14:03:44
Some guy posted that the syntax: delete top 1 from some_table works for deleting duplicates. I am pretty sure that doesnt work but I wanted to check just in case it did because it would be a really easy to delete duplicates.

The Yak Village Idiot

X002548
Not Just a Number

15586 Posts

Posted - 2007-03-20 : 14:11:20
I think ity depends on what verson you are using, but still, there are much better ways

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

jgrant
Yak Posting Veteran

69 Posts

Posted - 2007-03-20 : 14:51:26
I am using sql 2000. I want to add error checking for duplicates at the end of a stored procedure. So, I was thinking that I should insert the data into a temporary table if @@rowcount distinct column > 1 then first and then select distinct into the actual table where I am storing the data. If it returns @@rowcount = 0 then just insert directly into the table. Is this a good idea or is there a better idea for error checking and deleting duplicates?

The Yak Village Idiot
Go to Top of Page

Jeff Moden
Aged Yak Warrior

652 Posts

Posted - 2007-03-20 : 23:19:58
Create the staging table (temporary table) with a Primary Key that uses the IGNORE DUPES option to keep dupes out of the staging table. Then, do a cross check against the final target table using an outer join and only insert the rows that have no match. You do not need SELECT DISTINCT.

--Jeff Moden
Go to Top of Page
   

- Advertisement -