MySQL: What is the safest way to remove duplicate rows from a MySQL TABLE? -


i have mysql table. contains mailing addresses data feed. there no customer records mailing addresses, don't have easy way match customer record key see if exists in master table. i've decided have new daily data feed added master table , remove duplicates.

what safest way remove duplicates? obviously, want ignore id column field. how do following fields:

company_name contact_name address1 address2 address3 city state zipcode phone_number email_address 

what if rebuild mysql table include alter table unique key, safe? example:

alter table people add unique key (company_name,contact_name,address1,address2,address3,city,state,zipcode,phone_number,email_address) 

would above safely prevent duplicated records being inserted begin with?

thanks!

this simplest query can use choose max or min based on requirement.

delete mytable id not in ( select max(id) mytable group duplicatecolumn1, duplicatecolumn2, duplicatecolumn3) 

thanks


Comments