adspace


How to delete duplicate rows from table except one?

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

What are different types of constraints?

1003


What is the difference between upgrade and migration in sql server?

1185


Where can you add custom error messages to sql server?

1215


You have a stored procedure, which execute a lengthy batch job. This stored procedure is called from a trigger you do not want to slow the data entry process you do not want trigger to wait for this batch job to finish before it completes itself what you can do to speed up the process?

1216


Can one drop a column from a table?

1091


Explain system functions or built-in functions? What are different types of system functions?

1067


How can you append an identity column to a temporary table?

1071


Can you index views?

955


What are the different subsets of sql?

1655


How to remove duplicate rows from table except one?

1091


Does view occupy space?

1022


When should you use an instead of trigger?

1054


If any stored procedure is encrypted, then can we see its definition in activity monitor?

1073


How can I check that whether automatic statistic update is enabled or not?

1113


What is an indexed view?

1023