In MySQL I’m trying to write a Stored Procedure which does the following:
- Run a SELECT query which returns 1 row with 2 columns (so two pieces of information).
- Run an INSERT query which includes the two previous values returned and a few parameters which were passed into the stored procedure.
I was originally thinking I could store the two pieces of information from Step 1 into a variable, and then pass those into Step 2. After some reading though it seems that a variable in MySQL can only hold 1 piece of data. How can I get the 2 pieces of information from Step 1 into my INSERT statement in Step 2?
Thank you!
You can use INSERT INTO … SELECT.
Example,
Here you select
col1,col2fromtable2and add 2 new custom valuesvalue1andvalue2to the result set. This new 4 columns get inserted in to thetable1