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

To which devices can a backup be created and where should these devices be located? : sql server management studio

642


What do you mean by data manipulation language?

679


What are triggers in ms sql server?

698


What is the difference between a local and a global temporary table?

697


I have all the primary data files, secondary data files as well as logs. Now, tell me can I still restore the database without having a full backup? : sql server database administration

775






Do you know what are the properties of the relational tables?

665


Explain the architecture of ms sql reporting service?

606


How to copy the tables, schema and views from one sql server to another?

640


How to create a dml trigger using create trigger statements?

642


How to apply filtering criteria at group level with the having clause in ms sql server?

644


List out a number of the wants to setup a SQL Server failover cluster?

662


Can foreign key be deleted?

606


What are the different types of locks in the database?

559


Why would you use sql agent?

806


Explain can SSRS reports Cache results?

118