sql - Remove duplicate rows in MySQL -
sql - Remove duplicate rows in MySQL -
i have table next fields:
id (unique) url (unique) title company site_id
now, need remove rows having same title, company , site_id. 1 way using next sql along script (php):
select title, site_id, location, id, count( * ) jobs grouping 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 together unique
index on 3 columns. when write alter
statement, include ignore
keyword. so:
alter ignore table jobs add together 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...
sql mysql duplicate-removal
Comments
Post a Comment