Remove duplicate rows in MySQL

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

    I had to do this with text fields and came across the limit of 100 bytes on the index.

    I solved this by adding a column, doing a md5 hash of the fields, and the doing the alter.

    ALTER TABLE table ADD `merged` VARCHAR( 40 ) NOT NULL ;
    UPDATE TABLE SET merged` = MD5(CONCAT(`col1`, `col2`, `col3`))
    ALTER IGNORE TABLE table ADD UNIQUE INDEX idx_name (`merged`);
    

提交回复
热议问题