I'm sure this is simple I just cant get the correct search terms to find the answer. But I have one table for locations with IDs
ID| Name
1 | Foo
2 | Bar
3 | Blah
and another table (table2) that has a field referencing those location IDs:
ID| LocationID | Foo | Bar
1 | 1 | ... | ...
2 | 2 | ..
3 | 5 | ...
Where LocationId = a value from location. What I want to do is for every ID in location (1,2,3...) add a record to the other table. So for example:
"insert into table2 (locationID, foo, bar) values (1, "hello", "world");"
"insert into table2 (locationID, foo, bar) values (2, "hello", "world");"
and so on..
You can use INSERT INTO ... SELECT, so for your example
INSERT INTO table2 (locationID, foo, bar) SELECT ID, 'hello', 'world' FROM table1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With