mysql query inner join condition where id IN -


can suggest best way have simple query have 2 tables need update table 1 status column , if column 1 update table2. main question how when using id in ids

update table1 set status = 1 id in (ids) 

and if columnx each id 1 then

update table2 set status = 1 id 

not entirely sure mean, i'm guessing can use variant of update join, basic syntax like:

update table1 t1   join table2 t2     on t2.table1_id = t1.id    set t1.status = 1,        t2.status = case           when t1.columnx = 1 1 /* update if columnx 1 */          else t2.status             /* use old status if not  */        end case  t1.id in (...) 

if there low prevalence of columnx being 1 split out second part , separate query in transaction:

update table1 t1    set t1.status = 1  t1.id in (...)     update table2 t2   join table1 t1     on t1.id = t2.table1_id    , t1.columnx = 1    set t2.status = 1  t2.table1_id in (...)  

Comments