Thursday, February 18, 2021

My-SQL: Deleting all duplicate rows but keeping one row for table

MySQL Query :

DELETE FROM `Tablename` WHERE id NOT IN ( SELECT MIN(id) FROM (SELECT * FROM Tablename ) as t1 GROUP BY field1, field2, field3, field4, field5 ) 

Here fields are column on which you want to group the duplicate rows.