MySQL delete duplicate records but keep latest

后端 未结 7 1433

I have unique id and email fields. Emails get duplicated. I only want to keep one Email address of all the duplicates but with the latest id<

7条回答
  •  难免孤独
    2020-11-28 23:16

    Try this method

    DELETE t1 FROM test t1, test t2 
    WHERE t1.id > t2.id AND t1.email = t2.email
    

提交回复
热议问题