ReasyEasyPeasy ReasyEasyPeasy - 2 months ago 7
SQL Question

Insert into db2Table from an other table and own values

I have table1 and table2. I want to insert column a and column b from table1 into table2 and my own values (value1 and value2). The columns a and b are very big and that's why I don't want to import them into my java application. In addition I need a where condition for the a and b select. How should my preparedStatement looks like? I thought something like follows:

insert into table2 (columnvalue1, columnvalue2, a, b) as
(select a, b from table1 where value3 = ? and value4 = ?)

Answer

Something like:

insert into table2 (columnforvalue1, columnforvalue2, a, b)
    select value1, value2, a, b from table1 where value3 = ? and value4 = ?

Or

insert into table2 (columnforvalue1, columnforvalue2, a, b)
    select ?, ?, a, b from table1 where value3 = ? and value4 = ?