Remove duplicate records based on multiple columns?

前端 未结 7 2054
灰色年华
灰色年华 2020-12-04 07:46

I\'m using Heroku to host my Ruby on Rails application and for one reason or another, I may have some duplicate rows.

Is there a way to delete duplicate records base

7条回答
  •  自闭症患者
    2020-12-04 08:14

    You can try this sql query, to remove all duplicate records but latest one

    DELETE FROM users USING users user WHERE (users.name = user.name AND users.year = user.year AND users.trim = user.trim AND users.id < user.id);
    

提交回复
热议问题