How to delete duplicate records from a table?(for suppose in
a table we have 1000 Records in that we have 200 duplicate
Records , so ,how to findout that duplicate Records , how to
delete those Records and arranged into sequence order? one
more thing that there is no primary key at all)

Answers were Sorted based on User's Feedback



How to delete duplicate records from a table?(for suppose in a table we have 1000 Records in that w..

Answer / sneha

select distinct * from table into new_table;

delete table;

select * from new_table into table;

Is This Answer Correct ?    8 Yes 6 No

How to delete duplicate records from a table?(for suppose in a table we have 1000 Records in that w..

Answer / cp

DELETE FROM emp WHERE ROWID NOT IN(SELECT MAX(ROWID) FROM
emp GROUP BY empno)

Is This Answer Correct ?    2 Yes 3 No

How to delete duplicate records from a table?(for suppose in a table we have 1000 Records in that w..

Answer / smitha

;with empctc(empid,ename,sal,deptid,ranking)
as
(Select empid,ename,sal,deptid,ranking=Dense_rank() over (
partition by empid,ename,sal,deptid order by NEWID() asc)
from emp
)
delete * from empctc where ranking>1

Is This Answer Correct ?    2 Yes 5 No

How to delete duplicate records from a table?(for suppose in a table we have 1000 Records in that w..

Answer / sirisha

with numbered as(select rowno = row_number() over(partition
by empid order by empid),empname from employee)delete from
numbered where rowno > 1

Is This Answer Correct ?    1 Yes 6 No

How to delete duplicate records from a table?(for suppose in a table we have 1000 Records in that w..

Answer / pooja narang

We will get the duplicate records and insert them into a
new temp table by using below query:

select * into tmp_Employee
from Employee
having count(distinct *) > 1

Now delete the duplicate records from Employee table:

delete from Employee
having count(distinct *) > 1

Now insert the records from tmp_Employee to Employee table:

insert into Employee
select * from tmp_employee

drop table tmp_employee

Is This Answer Correct ?    4 Yes 15 No

Post New Answer

More SQL Server Interview Questions

application server is slow what may be the problem

0 Answers   Microsoft,


1.can we set the more than 1 primary keys for a table? 2.please give me the difference between Cluster Index and non-Clustered Index 3.can we use query like this "Select * from Table1,Table2;"

8 Answers  


What is relationship? What number of sorts of relationship are there?

0 Answers  


how do u do Performance tunning ?

1 Answers   Infodat Technologies, Satyam,


plz tell me the new features of sqlserver2000,sqlserver2002,sqlserver2005

3 Answers  






Describe about first three Normal forms.

1 Answers   HP,


How to get the definition of a view out of the sql server?

0 Answers  


How will you decide the active and passive nodes?

0 Answers  


What is lookup override?

0 Answers   Informatica,


Can we use where and having clause together?

0 Answers  


How to create a ddl trigger using "create trigger" statements?

0 Answers  


How many database files are there in sql server 2000?what are they?

0 Answers  


Categories