'Using Insert Into in SQL

I have 2 tables. Table 1 has a many columns, including fica_number, but not employee ID. Table 2 has many columns, including fica_number AND employee id. I wanted to use Insert Into to add the employee ID column from table 2 into table 1. I do not have full control over the database to alter table so I wanted to know if this approach would work.

insert into table1
select employee_id
from table2
join table1 on table1.fica_number= table2.fica_number

Because table1 does not have the employee_id, I am trying to have the employee_id from table 1 match with the fica number in employee 2. Im not sure if I should use where or join. Any suggestions? Thanks. The 2 tables look something like this

table1:

|...|fica_number|first_name|last_name|...|
|...|001-02-1234|Name1     |last1    |...|
|...|002-02-4321|Name2     |last2    |...|

table2:

|...|fica_number|first_name|last_name|employee_id|...|
|...|001-02-1234|Name1     |last1    |123456789  |...|
|...|002-02-4321|Name2     |last2    |012345678  |...|

I am trying to add the employee_id column from table2 into table1. An example is given above.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source