Search This Blog

SQL Delete Duplicate Records in a Table


 Often we get into the situation where we have duplicate rows or records in a table. Now let us see how to select and delete these duplicate rows or records. 

 
We can use the following SQL command to delete the duplicate rows or records in a table. Here the inner select subquery will identify the duplicate rows in the table.

DELETE FROM TableName a
WHERE
  a.rowid >
   ANY (
     SELECT b.rowid FROM TableName b
     WHERE
        a.column1 = b.column1
     AND
        a.column2 = b.column2
        );
 


Surely you will have to replace the TableName with the name of your table. And you will also replace the column1 and column2 with the columns of your own table.

No comments:

Post a Comment

Web Statistics