Mysql add mult-column index with repeated rows -
having next table:
id -> incremental field_1 -> foreignkey field_2 -> foreignkey
i want add next index
alter table my_table add unique index(field_1, field_2);
how ever have (due bad application validation) have lot of repeated rows (by repeated mean same field_1 , same field_2, having id difference)
the table has 60,000 rows so... removing field field hard.
how can apply index , remove every duplicated row?
create table mytable2 mytable; insert mytable2 select max(id), field_1, field_2 mytable group field_1, field_2; rename table mytable mytable_old, mytable2 mytable; alter table my_table add unique index(field_1, field_2)
Comments
Post a Comment