sql - Remove duplicate rows in MySQL -
i have table following fields:
id (unique) url (unique) title company site_id now, need remove rows having same title, company , site_id. 1 way using following sql along script (php):
select title, site_id, location, id, count( * ) jobs group site_id, company, title, location having count( * ) >1 after running query, can remove duplicates using server side script. but, want know if can done using sql query.
a easy way add unique index on 3 columns. when write alter statement, include ignore keyword. so:
alter ignore table jobs add unique index idx_name (site_id, title, company); this drop duplicate rows. added benefit, future inserts duplicates error out. always, may want take backup before running this...
wiki
Comments
Post a Comment