php - How to remove duplicate(fields) entries from a mysql db? -


i want remove duplicate records of table in mysql database. enter image description here

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

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -