how to delete duplicate rows from table

Answer Posted / navaneethakrishnan

Hi Kumar,

Yes it will delete only the id=1, you have to change the
id=2 whichever u want...

DELETE TOP(1) FROM [tblduplicate] WHERE [ID] = 2
DELETE TOP(1) FROM [tblduplicate] WHERE [ID] = 3

For ur kind information,.. it will delete the duplicate
records only if there is exactly 2 duplication...... if the
id 1 will entered to three times, this query will delete
only one record... because

as we enterd the query as top(1)it will select the top
most and delete the record..


This is the simple query to execute.... there is other ways
also.. to do....


Now use this query to do for more than 2 duplication

DELETE TOP(SELECT COUNT(*) -1 from dbo.tblduplicate where
id = 1)
from dbo.tblduplicate
where id = 1

Is This Answer Correct ?    1 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the datatype of rowid?

504


What method is used by the Command classes to execute SQL statements that return single values?

596


Why I am getting this error when dropping a database in ms sql server?

588


How many levels of sp nesting are possible?

549


What according to you is the difference between mysql and sql server performance?

556






how to restart sql server in single user mode? How to start sql server in minimal configuration mode? : Sql server database administration

458


How to delete a database in ms sql server?

557


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

558


How many columns can we include on clustered index ?

509


how you can get the list of largest tables in a database? : Sql server administration

546


Tell me what is sql profiler?

615


What is cdc in sql server?

568


What is temporal data type?

518


Can we use where clause with group by?

514


Write the queries for commands like Create Table, Delete table, Drop Table etc.

602