Remove duplicate rows leaving oldest row Only?

前端 未结 3 1590
暗喜
暗喜 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:20

    If you have a unique id for each row, you can try something like this. Don't ask me why exactly you need the second select statement, mysql won't let me execute otherwise. Also, group by whatever columns make your results unique.

    delete from my_table where id in (
      select id from (
        select id from my_table a group by subscriberEmail having count(*) > 1
      ) b
    );
    

提交回复
热议问题