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

Mention the differences between local and global temporary tables.

736


How to delete existing rows in a table?

763


Does group by sort data?

672


What are the acid properties?

719


How to recover from sql injection? : sql server security

699






Is truncate a dml command?

686


What is view in sql?

716


What is the user of Primary key?

737


What are sub reports?

168


What is a transactions?

778


How to execute stored procedure and set temp table in sql server?

737


Can I use sql azure as a backup with log shipping or database mirroring?

148


Explain “not null constraint” in sql server?

720


Explain the database you used in your final year project?

710


What is a constant or literal in ms sql server?

784