how to delete duplicate rows in sql server2005

Answer Posted / arunkumar_mlx

WITH A
AS
(
SELECT ROW_NUMBER() OVER ( PARTITION BY
columnname_1,columnname_2 ORDER BY columnname_1) AS
duplicate FROM table_name
)
SELECT * FROM A WHERE duplicate>1
--DELETE FROM A WHERE duplicate>1

First select and you can find the row_number having more
than 1 rows.

Then delete them on comment of select stmt inside the
query..
decomment of that delete stmt will delete the duplicate
rows.

Is This Answer Correct ?    8 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Other than truncate statement, which other command can by-pass the trigger on the tables?

617


What are the steps to follow to configure SQL*Net?

557


Can we update data in a view?

598


What are sparse columns?

584


You want to implement the many-to-many relationship while designing tables. How would you do it?

555






What is temporary stored procedure?

546


What is the difference between commit and rollback?

500


What is a rollup clause?

541


How to create a trigger for insert only?

595


How to get a list of columns in a view using the "sp_help" stored procedure?

566


What is the sql profiler?

537


What is cdc in sql server?

565


What causes index fragmentation?

572


What is recursion? Is it possible for a stored procedure to call itself or recursive stored procedure? How many levels of sp nesting are possible?

553


when you create a database how is it stored? : Sql server database administration

489