Remove duplicate rows in MySQL

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

    Simple and fast for all cases:

    CREATE TEMPORARY TABLE IF NOT EXISTS _temp_duplicates AS (SELECT dub.id FROM table_with_duplications dub GROUP BY dub.field_must_be_uniq_1, dub.field_must_be_uniq_2 HAVING COUNT(*)  > 1);
    
    DELETE FROM table_with_duplications WHERE id IN (SELECT id FROM _temp_duplicates);
    

提交回复
热议问题