Let's say I have a "source table" which holds some rows, in this case four. Now I'd like to insert new rows into a "target table" for each of the rows from the source table.
My current statement is:
SET @id = 1;
INSERT INTO target_table (id, value)
VALUES (@id, 1),
(@id, 2),
(@id, 3),
(@id, 4);
However I'd like to do something like this...
SET @id = 1;
myResultSet = SELECT value FROM source_table;
FOR EACH value in myResultSet
INSERT INTO target_table (@id, @value)
END
Insert ... Selectstatement