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

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -