I suck at SQL. I’ve had to google this question a few times and wasn’t able to find a good answer. Hopefully you will find this useful.
Context
You want to insert into table1, a specific column(s) from table 2 and a second column that is always the same value (for example, the number 2). How would you do this?
Code
insert into table1
select column1, column2, value1″, “value2” from table 2
Explanation
Insert is pretty self explanatory, you are inserting the values into table1.
The first part of the select is just selecting two columns from table 2 to add. Column1 and Column2 will be the first two columns to be inserted.
The second part of the select statement, “value1” and “value2” are the values you can insert and populate the whole column as. In our example, we would to populate a whole column full of 2s, all the way down.
Solution
Returning back to the contextual question
insert into table1
select column1, “2” from table 2
Hope you learned something useful!