Reputation: 11
I am trying to update the orgaization_id in location table which is primary key in Organization table.
update location set organization_id=org.old_id from organization as org
where location.old_id=org.old_id;
Facing syntax error please help..
Upvotes: 0
Views: 28
Reputation: 872
Please try the following code:
update location set organization_id=(select old_id from organization where organization.old_id=location.old_id);
Upvotes: 0
Reputation: 64466
You can use join to perform update from another table
update location l
join organization as o
on l.old_id=o.old_id
set l.organization_id=o.old_id;
Upvotes: 1