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

Tell me what is a linked server?

564


1)what is the difference between Reinitializing a Subscription and synchronization the subscription? 2)when to use reinitializing ? 3)when to use synchronization? 4)when adding table or deleting a table what to do?(reinz.. or syn) 5)when adding a column what to do?

1542


State the difference between local and global temporary tables?

564


Does group by or order by come first?

542


Explain why variables called the most powerful component of ssis?

534






What is the difference between substr and charindex in the sql server?

510


What are the approximate numeric data types?

533


What is the default value of an integer data type in sql server 2005?

586


Define inner join in sql server joins?

535


Explain transaction isolation levels in sql server?

551


What are distinctive joins find as a part of sql?

558


What is the difference between composite index and covering index?

509


Why use sub query in sql server and list out types of sub queries?

543


why would you call update statistics? : Sql server database administration

577


If you are given access to a SQL Server, how do you find if the SQL Instance is a named instance or a default instance?

668