Write a query to delete duplicate records in SQL SERVER

Answer Posted / rajnish kumar pandey

WITH TempTable(Col1, Col2, DuplicateCount)
AS
(
SELECT Col1, Col2,
ROW_NUMBER() OVER(PARTITION BY id, roles ORDER BY id) AS
DuplicateCount
FROM MainTable
)
DELETE
FROM TempTable
WHERE DuplicateCount > 1
GO

Is This Answer Correct ?    1 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How to list all columns in a table using odbc_columns()?

536


What is merge?

573


Write a query for primary key constraint with identity key word?

581


How we can compare two database data?

521


Explain what you mean by 3 tier architecture.

629






What are approximate numeric data types in ms sql server?

592


Define a cross join?

598


What are Row versions of DataRow?

611


What does select 1 mean?

534


What happens if you add a new index to large table?

513


Why we need to use secondry database file? though, we can do same work using primary database file also.

5777


What are pessimistic lock and optimistic lock?

550


What is a cursor, index in sql?

582


Explain concepts of analysis services?

515


Where can you add custom error messages to sql server?

587