mysql 删除重复 保留一行

Scroll Down

sql

delete from tableName where pk_id in (
  select pk_id from tableName
  where (column1, column2, column3)
    in (select column1, column2, column3
      from tableName group by column1, column2, column3 
        having count(1) > 1
      )
    and pk_id not in (
      select min(pk_id)  from tableName
      group by column1, column2, column3 having count(1) > 1 
    )
)