Remove duplicate rows in MySQL

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

    A really easy way to do this is to add a UNIQUE index on the 3 columns. When you write the ALTER statement, include the IGNORE keyword. Like so:

    ALTER IGNORE TABLE jobs
    ADD UNIQUE INDEX idx_name (site_id, title, company);
    

    This will drop all the duplicate rows. As an added benefit, future INSERTs that are duplicates will error out. As always, you may want to take a backup before running something like this...

提交回复
热议问题