I have a table named people_temp_1 that contains:
Name Age PersonID
John 25 1
Jane 32 2
Chris
It's one of the basics of SQL - use join. In your case it's better to use outer join
so you won't miss people from people_temp1
who don't have corresponding records in people_temp2
:
insert into people(name, age, profession, location)
select
p1.name,
p1.age
p2.profession,
p2.location
from people_temp1 as p1
left outer join people_temp2 as p2 on p2.id = p1.person_id