I have two tables that are very slightly different. Table A has 4 columns, and Table B has only 3. I want to copy all the data from Table B into Table A, but I also want to populate the extra column with the value 1
for every row.
This would work if not for the extra column:
insert into TABLEA (COL1, COL2, COL3) select COL1, COL2, COL3 from TABLEB;
Unfortunately, the extra column in Table A is not nullable, so I can't just run an update afterwards.
Thanks for any help!
Specify the column and use a constant for the value (note you can mix constants and column references in a select clause). In this case we're specifying every row will get the constant 1
for column COL4
.
insert into TABLEA (COL1, COL2, COL3, COL4)
select COL1, COL2, COL3, 1
from TABLEB;
insert into TABLEA (COL1, COL2, COL3, extra)
select COL1, COL2, COL3, 1
from TABLEB;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With