dontgav dontgav - 3 years ago 166
MySQL Question

insert data from table associated with other

In my MySQL database I have 1 table:

- client(id, name, adress, city)


I want to Create multiple adresses for 1 client, so i created new table

- adresse(id,id_client, adress, city)


i want to populate adress table with data imported from client table

for exemple i have data

id| name |adress|city
------|------|------|-------
1 | c1 | ad1 |paris
2 | c2 | ad2 |nice


i want my new table adress populated with data from client table juste like this

id| id_client|adress|city
------|----------|------|-------
1 | 1 | ad1 |paris
2 | 2 | ad2 |nice


I googled a lot and didn't find the solution

Answer Source

as far as i understood you want to import data from one table to another so you can do it below query

insert into adresse select * from client;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download