Insert row in table for each id in another table

If I understand correctly, you want one record in table2 for each record in table1.
Also I believe that apart from the reference to table1, table2 should initially contain blank rows.

So assuming

table1 (ID, field1, field2, ...)
table2 (ID, table1_ID, fieldA, fieldB,...)
-- where table1_ID is a reference to ID of table1

After creating table2 you can simply run this insert statement

insert into table2(table1_ID) 
select ID from table1

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)