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

Write a SQL query to make a column as unique?

634


Difference between connected and disconnected database in .net with sql server?

585


Which tcl commands are available on the sql server?

608


How to replace the Query Result 'Null Value' with a text ?

571


What is the name of the Database which IBM mainframe uses?

546






What is inner join in sql server joins?

554


Explain how dts is used to extract, transform and consolidate data?

589


Can a database be shrunk to 0 bytes, if not, why?

648


What is the maximum size of a row in sql server?

534


can a database be shrunk to 0 bytes, if not, why? : Sql server administration

615


What are the difference between primary key and unique key? : sql server database administration

532


What is your recommendation for a query running very slow? : sql server database administration

595


How do I view views in sql server?

525


What does it mean if @@cursor_row returns a negative number?

581


What is blocking and how would you troubleshoot it? : sql server database administration

602