UPDATE multiple rows in a MySQL table based on id existence in another table -



UPDATE multiple rows in a MySQL table based on id existence in another table -

i programmatically, i'm in learning mood today... looked around didn't find problem.

i have 2 tables item, person, , 3rd contains associations, item_person. not has item association doesn't exist. now, want maintain status column in item table partly based on whether item associated person. so...

table: item item_id description status table: person person_id name table: item_person item_id person_id

imagines want update item status 1 if association exists in item_person...

is there single mysql query can handle this?

is there single mysql query can update if association doesn't exist in item_person.

-- if association exists... update item bring together item_person ip on ip.item_id = i.item_id set i.status = 1 -- if association not exist... update item left bring together item_person ip on ip.item_id = i.item_id set i.status = 0 ip.item_id null

mysql

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -