pistacchio pistacchio - 14 days ago 5
SQL Question

Copy record to another table adding fields

I have 2 tables:

tab1
(
field1, field2, field3
)

tab2
(
field1, field2,field3, field4
)

I want to copy a record from
tab1
to
tab2
taking all the fields and adding a value for
field4
.

How can I select
field1
,
field2
and
field3
from
tab2
and also add a value? I know that
SELECT
and
VALUES
in a
INSERT
query are mutually exclusive.

Thanks in advance.

Gustavo.

Answer

I don't know Oracle, but in Ms SQL it works like this:

insert into tab2 (field1, field2, field3, field4) 
select field1, field2, field3, 'New Value' from tab1