Remove duplicate rows in MySQL

前端 未结 25 3473
囚心锁ツ
囚心锁ツ 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:17

    If the IGNORE statement won't work like in my case, you can use the below statement:

    CREATE TABLE your_table_deduped LIKE your_table;
    
    
    INSERT your_table_deduped
    SELECT *
    FROM your_table
    GROUP BY index1_id,
             index2_id;
    
    RENAME TABLE your_table TO your_table_with_dupes;
    
    RENAME TABLE your_table_deduped TO your_table;
    
    #OPTIONAL
    ALTER TABLE `your_table` ADD UNIQUE `unique_index` (`index1_id`, `index2_id`);
    
    #OPTIONAL
    DROP TABLE your_table_with_dupes;
    

提交回复
热议问题