Posted By

welancers on 10/12/12


Tagged

delete duplicate


Versions (?)

Delete duplicate records from MySQL Database


 / Published in: MySQL
 

Use the same table to query against itself. The greater then sign does the main job of returning only one records of both duplicate records.

  1. DELETE FROM table1
  2. USING table1, table1 AS vtable
  3. WHERE (
  4. table1.ID > vtable.ID
  5. )
  6. AND (
  7. table1.field1 = vtable.field1
  8. )
  9. AND (
  10. table1.field2 = vtable.field2
  11. )
  12. AND (
  13. table1.field3 = vtable.field3
  14. )
  15. AND (
  16. table1.field4 = vtable.field4
  17. )

Report this snippet  

You need to login to post a comment.