Remove duplicate rows in MySQL

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

    I have this query snipet for SQLServer but I think It can be used in others DBMS with little changes:

    DELETE
    FROM Table
    WHERE Table.idTable IN  (  
        SELECT MAX(idTable)
        FROM idTable
        GROUP BY field1, field2, field3
        HAVING COUNT(*) > 1)
    

    I forgot to tell you that this query doesn't remove the row with the lowest id of the duplicated rows. If this works for you try this query:

    DELETE
    FROM jobs
    WHERE jobs.id IN  (  
        SELECT MAX(id)
        FROM jobs
        GROUP BY site_id, company, title, location
        HAVING COUNT(*) > 1)
    

提交回复
热议问题