mysql get data from one table to another, while grouping records and extra fields -
ok, explain first have, , need result.
basicly, have phonebook, phonebook has duplicate records "company" while duplicate records not duplicate... :\
i think example explain better:
demo records:
1. company a, address a, phone 2. company a, address a, phone b 3. company a, address a, phone c 4. company a, address b, phone
what want, make new table, filled "company a", "address a" phone numbers 1 records, result should like: company a, address a, phone a, phone b, phone c etc..
the second problem "company a" can bit diffrent, example:
1. company xyz, address a, phone 2. company abc, address a, phone
i dont know how start this. thinking of doing coding c# application, think there might easier solution using pure mysql.
your way not maintain normalization,
however, following might looking for
create new table:
create table new_table ( company_a varchar(255), address_a varchar(255), phone_a varchar(255), phone_b varchar(255), phone_c varchar(255) ); // define index
insert new table:
assuming phone not contains ,
insert new_table select company, address, substring_index(group_concat(phone), ',', 1) phone_a, substring_index( substring_index(group_concat(phone), ',', 2), ',', -1 ) phone_b, substring_index(group_concat(phone), ',', -1) old_table group company, address;
Comments
Post a Comment