php - How to remove duplicate(fields) entries from a mysql db? -
i want remove duplicate records of table in mysql database. 
in image id auto increment want customer_invoice_id unique want delete duplicate record. e.g want delete 1104 record, delete 1105 latest record query.
alter ignore table table add unique key idx1(customer_invoice_id);
before set constraint, manual delete first.
delete tablename left join ( select customer_invoice_id, max(id) id tablename group customer_invoice_id ) b on a.customer_invoice_id = b.customer_invoice_id , a.id = b.id b.customer_invoice_id null this preserve latest record every customer_invoice_id. , can execute statement,
alter table tablename add unique key idx1(customer_invoice_id) demo,
Comments
Post a Comment