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

Answer Posted / madhur/amrutha

select ROW_NUMBER() OVER (ORDER BY names ASC) AS ROWID, *
into #temp from emp
select * from #temp where ROWID not in(
select b.ROWID from
(
select ROW_NUMBER() OVER (ORDER BY names ASC) AS ROWID, *
from emp
except
SELECT ROW_NUMBER() OVER (ORDER BY names ASC) AS ROWID, *
FROM
(
select names , sal from emp
union
select distinct names,sal from emp) as a ) as b)

drop table #temp

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

can a database be shrunk with users active? : Sql server administration

567


What is self join in sql server joins?

560


What is nested transaction?

536


What is an identity?

572


what are the core components of SSRS?

92






How to find table changes in sql server?

663


What is “begin trans”, “commit tran”, “rollback tran” and “savetran”?

586


What is the datatype of rowid?

510


What command is used to create a database in the sql server and how?

604


Define tempdb database?

595


How to provide default values to stored procedure parameters?

578


How do indexes help, types?

553


What is forward - only cursors / read only cursor?

523


What are trace files?

535


What is normalization? Explain its different types?

604