Saturday, 5 May 2018

Deleting rows with duplicate values from a table


The following query can be used to delete rows with duplicate values from a table. This is very useful when the table is large and there are a lot of duplicate values.



The table must have a primary key or other unique field which can be used to identify the duplicate records. If the table does not have a primary key or other unique field it can be added. See my post Adding a primary key to a table.

Example:

In this example id is the primary key and student_no 000113, 000313, 000413. 000613 and 000913 are duplicated.

The following query will delete the duplicate rows:


The result:



No comments:

Post a Comment