Remove duplicate rows leaving oldest row Only?

前端 未结 3 1591
暗喜
暗喜 2020-11-29 09:48

I have a table of data and there are many duplicate entries from user submissions.

I want to delete all duplicates rows based on the field subscriberEmail

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-29 10:11

    How about this, now you don't have to create any temporary tables using self joins

    DELETE u1 FROM users u1, users u2 WHERE u1.id < u2.id AND u1.email = u2.email
    

    To check if there are any duplicate records in table

    SELECT count(*) as Count, email FROM users u group by email having Count > 1
    

提交回复
热议问题