Alan Han
Alan Han

Reputation: 960

Oracle insert from select into table with more columns

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

Answers (3)

Matt Dodge
Matt Dodge

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

Andrew
Andrew

Reputation: 359

Put 0 as default in SQL or add 0 into your area of table

Upvotes: 5

Otávio Décio
Otávio Décio

Reputation: 74290

just select '0' as the value for the desired column

Upvotes: 1

Related Questions