I need to Insert two Records in a new mysql table for each record in another table
example:
table1
id, name
1, Patrick
2, John
I want to insert favorite site for each records in the second table and each record should have facebook and google as default
the second table should looks like:
table2
table1_id, site
1, facebook
1, google
2, facebook
2, google
2
Answers
We can multiply the original table with a fixed list of rows with a
cross join
:In recent MySQL versions (>= 8.0.19), the
VALUES
statement makes the syntax neater:This is an other way to do it using
inner join
Demo here