Geeks With Blogs
Information -> Source for Next Generation brcraju@hotmail.com
Simple way to Remove Duplicate Rows from an Existing Table in SQL

SELECT DISTINCT *
INTO duplicate_table
FROM original_table
GROUP BY key_value
HAVING COUNT(key_value) > 1

DELETE original_table
WHERE key_value
IN (SELECT key_value
FROM duplicate_table)

INSERT original_table
SELECT *
FROM duplicate_table

DROP TABLE duplicate_table
Posted on Thursday, October 23, 2003 10:47 AM SQLServer | Back to top


Comments on this post: Removing Duplicates

# re: Removing Duplicates
Requesting Gravatar...
Nice. Had to insert individual columns into select and group clauses, but this did the trick. I might use a temp table in db's that support it. Thanks,

ZGrinch
Left by ZGrinch on Dec 10, 2003 10:01 PM

# re: Removing Duplicates
Requesting Gravatar...
very good
Left by 疣迪 on Aug 16, 2005 8:03 AM

# re: Removing Duplicates
Requesting Gravatar...
very good
Left by 儿童 on Sep 09, 2005 1:48 PM

# re: Removing Duplicates
Requesting Gravatar...
hi
Thanks ,
This is a extremly good query.
This is a good experience for me. Thank u so much.

Regards
Ragesh.p.p
Left by ragesh on Nov 23, 2006 7:07 PM

Your comment:
 (will show your gravatar)
 


Copyright © Raju | Powered by: GeeksWithBlogs.net | Join free