The same table to delete duplicate data

The same table, to assume that the only two fields do business, these two fields are key1, key2,

These two fields are the only places

DELETE tablename FROM
    t_price_insignt_profit ,
    (
        SELECT
            min(id) id,
           key1, key2
        FROM
            tablename 
        GROUP BY
            
            key1, key2
        HAVING
            count(*) > 1
    ) t2
		WHERE
 tablename .key1=t2.key1 
AND tablename .key2=t2.key2
AND tablename .id > t2.id;

  

Guess you like

Origin www.cnblogs.com/stevenlii/p/11671005.html