Question

(MySQL) I am trying to migrate a "subscription" table into 3 new tables: "product", "subscription", "actual" where "actual" is the name of the actual product, say, newsletter. The subscription has a FK reference to product and the actual has FK reference into subscription.

I know the INSERT INTO SELECT statement can copy data probably from many table to one; is there a statement to do the opposite, one to many tables for my case?

Was it helpful?

Solution

I'm not aware of an SQL statement that will do what you want. Just do several INSERT INTO SELECTs one after the other. It may be faster to do them one at a time anyway.

OTHER TIPS

I think you can use three seperate insert into select statements. First you convert the product table, then the subscription where you can use an embedded select to find the id in the product table:

insert into subscription (some_column, FK_id,...)
select something, (select id from product where <your where clause>),... 

and finally convert the actual table using an embedded select to get the id from the subscription table.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top