3
My address book table has many duplicated addresses for each client. Note in the image below that I have many duplicate Zip Codes for the same client with ID 12.
I need to remove duplicate addresses where postcode
and parent_id
are greater than 1 and maintain an address in the same condition, ie have to maintain a 14402-408, 14403-707, 60150-170 and 81050-130.
In a simple way I would need the following:
DELETE * FROM catalog_address
WHERE parent_id AND postcode > 1
I could not find similar case, I saw enough questions to remove duplicates as below: How to delete all duplicates except one?, but in my opinion it doesn’t solve my case.
How would the MYSQL instruction for this case?
Thank you!
Possible duplicate of How to delete all duplicates except one?
– Sorack
Sorry @Sorack, my forte is not MYSQL, but it seems that the possible answer attached does not answer my question, because I have to test if condition A and B are greater than 1 to delete.
– Diego Queiroz
I don’t have MYSQL here to check, but you can test something like this: delete from catalog_address Where postcode = '14402-408' and rowid not in (select min(rowid) from catalog_address Where postcode = '14402-408' )
– Reginaldo Rigo
@Diegoqueiroz, do you have an id field in this table? Because without it it will not be possible to remove duplicates.
– Roberto de Campos
I have an auto increment field named entity_id @Robertodecampos.
– Diego Queiroz