How to retrieve duplicate rows in a table?
How to delete the duplicate entries in a table?

Answer Posted / samba shiva reddy . m

How to retrieve the duplicate rows in table :

select * from emp group by empid,empname having count(empname)>1

How to delete the duplicate rows in table :
1.inserting distinct rows in temp table variable
2. deleting emp table
3.Again inserting into emp table from temp table variable


declare @temp table
(empid int,empname varchar(50))
insert into @temp
select * from emp group by empid,empname having count(empname)>0
delete from emp
insert into emp
select * from @temp
select * from emp

Is This Answer Correct ?    1 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is attribute? : sql server analysis services, ssas

591


What is a database in ms sql server?

555


What is difference between rownum and rowid?

511


What is a covering index?

536


What is normalization? Explain different forms of normalization?

545






Why is the need for data conversion transformations?

506


What is 1nf normalization form?

601


How much memory that we are using in Logshipping Concept?

1370


How to configure and test odbc dsn settings?

577


When does the auto update index statistics feature in sql server turn itself on?q) what specific conditions database should meet, before you can bulk copy data into it using bcp?

583


explain the storage models of olap? : Sql server database administration

524


What is temporary table in sql server? Why we use temp table?

522


What is normalization and denormalization in sql server?

541


Explain “row_number()” in sql server with an example?

524


Where can you find the error log information? : sql server database administration

568