Remove duplicate rows in MySQL

前端 未结 25 4275
囚心锁ツ
囚心锁ツ 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条回答
  •  梦毁少年i
    2020-11-21 05:25

    To Delete the duplicate record in a table.

    delete from job s 
    where rowid < any 
    (select rowid from job k 
    where s.site_id = k.site_id and 
    s.title = k.title and 
    s.company = k.company);
    

    or

    delete from job s 
    where rowid not in 
    (select max(rowid) from job k 
    where s.site_id = k.site_id and
    s.title = k.title and 
    s.company = k.company);
    

提交回复
热议问题