Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebird sql to insert a typical record from another table with only one different field

I work on Firebird 2.5 and I have two tables, all their columns are similar except one has a primary key with auto increment and a not null foreign key field (A) for master table

I know I can use sql like this to insert all values from the two tables

 insert into table1 select * from table2 where somthing = 'foo'

but what about the field (A) is there any way to insert this value manually in the same sql statement ? as this is the only field need to be entered manually

Thanks

like image 523
Welliam Avatar asked Jan 20 '23 04:01

Welliam


1 Answers

You can specify both the source and target fields explicitly (and you should; don't use select * unless you have a specific reason to):

insert into table1
(
    col1,
    col2,
    col3,
    col4
)
select
    col1,
    col2,
    col3,
    'foo'

from table2

where something = 'foo'
like image 161
Adam Robinson Avatar answered Jan 21 '23 18:01

Adam Robinson