Reputation: 960
I want to insert to a table from a select statement, however, there are 3 columns returned from the select statement and the table has 4 columns, I would like to add 0 for all rows in the extra column. Can anyone give me a sample SQL query for that?
Thank you!
Upvotes: 70
Views: 235335
Reputation: 11142
Just add in the '0' in your select.
INSERT INTO table_name (a,b,c,d)
SELECT
other_table.a AS a,
other_table.b AS b,
other_table.c AS c,
'0' AS d
FROM other_table
Upvotes: 131
Reputation: 74290
just select '0' as the value for the desired column
Upvotes: 1