KavanaNaveen
KavanaNaveen

Reputation: 11

Update error in mysql Query taking data from another table

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

Answers (2)

jun drie
jun drie

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

M Khalid Junaid
M Khalid Junaid

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

Related Questions