我有2个表department_referance和department在department_referance中的代码等于department表中的department_string_id。
department_referance //table
id code sl_flag
DD01 1
department //table
department_id department_string_id sl_flag
DD01
我想从department_referance获取sl_flag值并更新department表的sl_flag中的值。
update sl_flag='(SELECT a.sl_flag FROM department_referance a inner JOIN department b on a.code=b.department_string_id)'
答案 0 :(得分:2)
您可以通过加入(JOIN
)两个表来更新它。
<强>查询强>
update `department ` t1
join `department_referance ` t2
on t1.`code` = t2.`department_string_id`
set t1.`sl_flag` = t2.`sl_flag`;
答案 1 :(得分:2)
您可以使用此查询
UPDATE department d
join department_referance
dr on dr.code = d.department_string_id
set d.sl_flag = dr.sl_flag