How do I delete all the duplicate records in a MySQL table without temp tables

前端 未结 9 1372
北恋
北恋 2020-11-27 03:46

I\'ve seen a number of variations on this but nothing quite matches what I\'m trying to accomplish.

I have a table, TableA, which contain the answers gi

9条回答
  •  旧时难觅i
    2020-11-27 04:14

    Tested in mysql 5.Dont know about other versions. If you want to keep the row with the lowest id value:

    DELETE n1 FROM 'yourTableName' n1, 'yourTableName' n2 WHERE n1.id > n2.id AND n1.member_id = n2.member_id and n1.answer_num =n2.answer_num
    

    If you want to keep the row with the highest id value:

    DELETE n1 FROM 'yourTableName' n1, 'yourTableName' n2 WHERE n1.id < n2.id AND n1.member_id = n2.member_id and n1.answer_num =n2.answer_num
    

提交回复
热议问题