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

Suppose we have a table "MyTable" containing 10 rows, what query should be executed to update the odd rows "Salary" as 9000?

583


What is the use of keyword with encryption. Create a store procedure with encryption?

587


What is exclusive locks?

540


What are the different kinds of ssrs reports?

170


What is executereader?

555






How to drop an existing user defined function in ms sql server?

570


Explain difference between control flow and data flow?

535


How can we delete a table in sql server?

556


Explain what is the difference between a local and a global temporary table?

517


Is BCNF better than 2NF & 3NF? Why?

625


Does index slows down insert statements?

587


How to insert data into an existing table?

571


How many types of schemas are there?

531


How many types of built in functions are there in sql server 2012?

493


whats new about truncate in sql server 2008?

2030