Write a query to delete duplicate records in SQL SERVER

Answer Posted / senthilsjc

This query delete duplicate records(but not delete both
duplicate)
set rowcount 1
delete yourtable
from yourtable a
where (select count(*) from yourtable b where b.name=a.name
and b.age=a.age)>1
while @@rowcount >0
delete yourtable
from yourtable a
where(select count(*) from yourtable b b.name=a.name and
b.age=a.age)>1
set rowcount 0

Is This Answer Correct ?    6 Yes 12 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

let's assume you have data that resides on sql server 6.5. You have to move it sql server 7.0. How are you going to do it? : Sql server database administration

510


role of sql sever 2005 in database rather than any other database

1515


Is truncate a dml command?

506


What is the difference between clustered and non-clustered indexes in ms sql server?

499


Explain the difference between function and stored procedure?

523






What are trace flags and mention a few common trace flags used with sql server?

557


What command would you use to add a column to a table in sql server?

756


What is failover clustering overview?

595


Can sql servers link to other servers?

569


What is the recommended total size of your memory optimized tables?

536


What is the maximum length of an alert name?

610


How to use go command in "sqlcmd"?

652


What is xml datatype?

667


Write an SQL query to obtain the 2nd highest salary.

617


explain different types of constraints? : Sql server database administration

520