Back to Top

Delete only duplicate values from a Table



How to delete the duplicate records from the table in SQL Server Database

Intro: Delete query is used to remove the records from a table in the Database. Delete is the query in the database where data can be revoked.
There are so many options can be used to delete the records from the table of a DB. So following ways can be opted to delete the duplicate values from a table in SQL.


  • SOLUTION 1: 


  • delete top(1) from  table where id=7507089 and transid=3991711  
                This query can be used only if we want to delete the records one by one having the               duplicate value of data.                                                                                                                                            

  • SOLUTION 2: 
    
  • delete from table  where id=7507089 and Transid =3991711 and  transid not in (select top(1)  from table where Transid =3991711)  
The above query will result you saving one value where Transid =3991711 and will delete all the values that is having Transid =3991711 AND id=7507089






0comments

Post a Comment