MySQL multi-field joint deduplication eliminates duplicate data retention of a minimum id

DELETE FROM table name WHERE (field 1, field 2, field 3) 
the IN 
(the SELECT field 1, field 2, field 3 FROM (SELECT field 1, field 2, field 3 the FROM table GROUP BY field 1, field 2, field 3 the HAVING COUNT (*)> 1) S1) 
the AND 
ID the NOT the IN (the SELECT min (ID) AS ID the FROM (the SELECT ID the FROM table GROUP BY field 1, field 2, field 3 HAVING COUNT (*)> 1 ) s2);

 

Reference  https://www.cnblogs.com/XiaoMingBlingBling/p/11146375.html  modify the last sub-query id is min (id) as id

Guess you like

Origin www.cnblogs.com/dblock/p/12109362.html