update文で相関サブクエリ
table_a table_b w value w value -- -- -- -- 1 9 1 3 2 9
table_a.wとtable_b.wを結合し、table_a.value列をtable_b.value列の値で更新する。
table_a.wに結合するtable_b.wの値が存在しないときは0で更新する。
update table_a a set value = case when exists(select 1 from table_b b where b.w = a.w) then (select b.value from table_b b where b.w = a.w) else 0 end;
更新結果
table_a w value -- -- 1 3 2 0