1

I want to copy datas from the first table to another table. Both tables have common columns. This is the representation

table1 has already data. table 1:

id | employeeName | sectionCode | teamCode| day1 | day2 |
1     eric            400            315

and table2 has no data yet. table 2:

id | employeeName | sectionCode | teamCode | day1_a | day_b |

i want to copy the data inside table 1 to table 2 but only the common columns. So that i don't need to enter data in table 2 manually.

i tried this question but it's different.

1

1 Answer 1

2

Explicity name the "common" columns in the target table and select only those:

insert into table2 (id, employeeName, sectionCode, teamCode)
select id, employeeName, sectionCode, teamCode
from table1

This assumes that the other columns are defined with default value or are nullable. If not, or alternatively, you can omit naming the target columns if you provide values (or expressions) for the other columns so all columns have values provided for them:

insert into table2
select id, employeeName, sectionCode, teamCode, 'foo', 'bar'
from table1
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.