How to delete duplicate rows from table except one?



How to delete duplicate rows from table except one?..

Answer / Ajay Kumar Sharma

"To delete duplicate rows from a table while keeping only one, you can use the ROW_NUMBER() window function. Here's an example:nnWITH CTE AS (n SELECT *, ROW_NUMBER() OVER(PARTITION BY column1, column2 ORDER BY column3) rnn FROM yourTablen)nDELETE CTE WHERE rn > 1".

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More SQL Server Interview Questions

Define full outer join?

1 Answers  


Write a program using SQL queries to find a unique entry in a table.

1 Answers   Tech Mahindra,


how to overcome kernel isssues

1 Answers   Fortune,


What is the usage of the sign function?

1 Answers  


What is an execution plan? How would you view the execution plan?

1 Answers  


Define synonym?

1 Answers  


What are the differences between lost updates and uncommitted dependencies?

1 Answers  


What does the on update no action do?

1 Answers  


Where do we generally create INDEX?

1 Answers   Ernst Young, Thomson Reuters,


Explain filtered indexes?

1 Answers  


Can a stored procedure call itself or recursive stored procedure? How many levels sp nesting is possible?

1 Answers  


List out different types of normalizations in sql server and explain each of them?

1 Answers  


Categories