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 you tell me some of the common replication dmv's and their use? : sql server replication

537


What is dimension table? : sql server analysis services, ssas

562


What is wrong with sql server client libarary dll, ntwdblib.dll?

563


how to overcome kernel isssues

1174


Explain partitioned view?

591






What is built-in/administrator?

578


Can you explain what are the restrictions applicable while creating views? : SQL Server Architecture

496


Why do we use trigger?

559


How can I add Reporting Services reports to my application?

91


Explain user defined functions?

621


What is the importance of concurrency control?

665


What are constraints in microsoft sql server?

565


Can binary strings be converted into numeric or float data types?

561


what are the reporting service components in SSRS?

118


How to call stored procedure using http soap?

522