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

Answer Posted / nagabhushan adhikari

These are duplicates....

select distinct(col1),col2,col3.... into #temp from table
group by col1 having count(1) > 1

by the below delete duplicates
delete table from table A, #temp B where A.col1= B.col1

by this insert only a single record
insert into table select col1, col2,col3... from #temp

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Issues related in upgrading SQL Server 2000 to 2005 / 2008

1511


You want to check the syntax of a complicated update sql statement without executing it. What command should you use?

493


What is the purpose of optimization?

548


What is a performance monitor?

560


Does dbcc checkdb requires db to be in single_user mode? : sql server database administration

525






How to create new table with "create table" statements?

566


What are the steps to take to improve performance of a poor performing query? : sql server database administration

602


Explain optimistic and pessimistic concurrency?

548


What is the difference between TRUNCATE and DROP?

633


Explain user defined views?

581


Your sql server is running out of disk space. You notice that there are several large files with ldf extensions what are these files?

621


How to create new tables with "select ... Into" statements in ms sql server?

518


where the connection string store in the database

1534


How to optimize stored procedure optimization?

525


What is key set driven?

545