Remove duplicate rows in MySQL

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

    This will delete the duplicate rows with same values for title, company and site. The first occurrence will be kept and rest all duplicates will be deleted

    DELETE t1 FROM tablename t1
    INNER JOIN tablename t2 
    WHERE 
        t1.id < t2.id AND
        t1.title = t2.title AND
        t1.company=t2.company AND
        t1.site_ID=t2.site_ID;
    

提交回复
热议问题