语法:UPDATE 表1 t1 SET t1.字段值1 =(SELECT t2.字段值2 FROM 表2 t2 WHERE t1.关联字段1 = t2.关联字段2) WHERE 条件表达式;
举例:
UPDATE t_core_device d SET d.trade_id =(SELECT p.trade_id FROM t_core_program p WHERE p.id = d.program_id) WHERE d.trade_id IS NULL;
解释:当t_core_device表的trade_id字段为空时,更新值=关联的t_core_program表中的trade_id.