且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MySQL更新列与另一个表中的值

更新时间:2022-02-27 22:42:53

除了此答案之外,如果您需要根据tableA.value动态更改tableB.value,则可以执行以下操作:

In addition to this answer if you need to change tableB.value according to tableA.value dynamically you can do for example:

UPDATE tableB
INNER JOIN tableA ON tableB.name = tableA.name
SET tableB.value = IF(tableA.value > 0, tableA.value, tableB.value)
WHERE tableA.name = 'Joe'