Remove duplicate rows in MySQL

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

    In Order to duplicate records with unique columns, e.g. COL1,COL2, COL3 should not be replicated (suppose we have missed 3 column unique in table structure and multiple duplicate entries have been made into the table)

    DROP TABLE TABLE_NAME_copy;
    CREATE TABLE TABLE_NAME_copy LIKE TABLE_NAME;
    INSERT INTO TABLE_NAME_copy
    SELECT * FROM TABLE_NAME
    GROUP BY COLUMN1, COLUMN2, COLUMN3; 
    DROP TABLE TABLE_NAME;
    ALTER TABLE TABLE_NAME_copy RENAME TO TABLE_NAME;
    

    Hope will help dev.

提交回复
热议问题