Remove duplicate rows in MySQL

前端 未结 25 3431
囚心锁ツ
囚心锁ツ 2020-11-21 04:33

I have a table with the following fields:

id (Unique)
url (Unique)
title
company
site_id

Now, I need to remove rows having same titl

25条回答
  •  有刺的猬
    2020-11-21 05:22

    I have a table which forget to add a primary key in the id row. Though is has auto_increment on the id. But one day, one stuff replay the mysql bin log on the database which insert some duplicate rows.

    I remove the duplicate row by

    1. select the unique duplicate rows and export them

    select T1.* from table_name T1 inner join (select count(*) as c,id from table_name group by id) T2 on T1.id = T2.id where T2.c > 1 group by T1.id;

    1. delete the duplicate rows by id

    2. insert the row from the exported data.

    3. Then add the primary key on id

提交回复
热议问题