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

Popular posts from this blog

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -

Asterisk AGI Python Script to Dialplan does not work -