mysql - SQL - Update Junction Table Based on Values in User Table -


i have new migration creates many-to-many relationship between user , organization through junction table called organization_member. since trying migrate current values of organization_id , user_id on user table junction table represent relationship, thought try join , update, can't seem figure out how query both tables , take existing columns on user , update relationship doesn't exist. here original thought:

update `om` set `om`.`user_id` = `u`.`user_id`, `om`.`organization_id` = `u`.`organization_id` `user` `u` left join `organization_member` `om` on `u`.`user_id` = `om`.`user_id` `u`.`organization_id` not null; 

but error @

'from `user` `u` left join `organization_member` `om` on `u`.`user_id` = `o' @ line 3 

any great!

in mysql, join part of update. there no separate from:

update `user` `u` join        `organization_member` `om`        on `u`.`user_id` = `om`.`user_id`     set `om`.`user_id` = `u`.`user_id`,         `om`.`organization_id` = `u`.`organization_id`     `u`.`organization_id` not null; 

a left join inappropriate. want update om, need matching row update


Comments

Popular posts from this blog

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -