Greetings guys, ive stumbled upon a tricky problem here, i want to achieve this in under 1 command text, imaginee i have a table_a with some template data so i can fill table_b with said template data and 2 more column referencing the IDs as parameters, for example:
SET @Last_ID=LAST_INSERTED_ID(); INSERT INTO table_a (col1, col2, col3) SELECT (col1,@Last_ID, col3) FROM table_b;
Is this sort of thing even achievable?
Please leave comment below if you guys need more clarifications.
Best Regards,
Eugen.
What I have tried:
I know i can do it by 2 separate commands, get all the data from table_b into program into some datatable and then inserting the data into table_a by spamming the insert clause per line example:
SELET col1, col2 from table_b WHERE col3=@col3ParameterValue;
Insert into table_a (col1, col2, col3) Values (@col1_1, @col2_1, @col3_1), (@col1_2, @col2_2, @col3_2), (@col1_3, @col2_3, @col3_3), (@col1_4, @col2_4, @col3_4), (@col1_5, @col2_5, @col3_5), (@col1_6, @col2_6, @col3_6), (@col1_7, @col2_7, @col3_7), (@col1_8, @col2_8, @col3_8), (@col1_9, @col2_9, @col3_9)...
but this is unneficient and i do not want to resort to this method.