posts - 50, comments - 92, trackbacks - 171

My Links

News

Article Categories

Archives

Post Categories

Image Galleries

Friends Blog

Removing Duplicates

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

Print | posted on Thursday, October 23, 2003 10:47 AM | Filed Under [ SQLServer ]

Feedback

Gravatar

# re: Removing Duplicates

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
12/10/2003 10:01 PM | ZGrinch
Gravatar

# re: Removing Duplicates

very good
8/16/2005 8:03 AM | 疣迪
Gravatar

# re: Removing Duplicates

very good
9/9/2005 1:48 PM | 儿童
Gravatar

# re: Removing Duplicates

hi
Thanks ,
This is a extremly good query.
This is a good experience for me. Thank u so much.

Regards
Ragesh.p.p
11/23/2006 7:07 PM | ragesh
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 

Powered by: