Remove duplicate rows in MySQL

前端 未结 25 3659
囚心锁ツ
囚心锁ツ 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条回答
  •  旧时难觅i
    2020-11-21 05:28

    The faster way is to insert distinct rows into a temporary table. Using delete, it took me a few hours to remove duplicates from a table of 8 million rows. Using insert and distinct, it took just 13 minutes.

    CREATE TABLE tempTableName LIKE tableName;  
    CREATE INDEX ix_all_id ON tableName(cellId,attributeId,entityRowId,value);  
    INSERT INTO tempTableName(cellId,attributeId,entityRowId,value) SELECT DISTINCT cellId,attributeId,entityRowId,value FROM tableName;  
    TRUNCATE TABLE tableName;
    INSERT INTO tableName SELECT * FROM tempTableName; 
    DROP TABLE tempTableName;  
    

提交回复
热议问题