以下写法针对MySQL。
虽然写子查询也是可以实现的,不过当然应该选择一种更有效率的方式:
- update table1 t1 left join table2 t2 on t1.key=t2.key set
- t1.field1=t2.field1,
- t1.field2=t2.field2,
- t1.field3=t2.field3
- where t1.field4 is null and t2.field4 > '2017-04-27';
该方式也比较灵活,ON条件和WHERE条件按需添加。
本文介绍了一种高效的MySQL更新方法,通过使用LEFT JOIN结合ON和WHERE条件来更新table1中的field1, field2, 和 field3字段,仅当table1的field4为空且table2的field4大于'2017-04-27'时执行。
1806

被折叠的 条评论
为什么被折叠?



