Pages

Thursday, February 27, 2014

How to delete duplicate records in sql

Delete from Student a1 where a1.rowid < (select max(rowid) from Student a2 where a2.name=a1.name);


Explaination:

For each row in Outer query, inner query runs for complete table checking the equal condition and returns maximum row id and if this maximum row id is greater then the row-id of outer query then delete the row. and this is done for each row of outer query.