且构网

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

mysql用另一个表中的值更新列

更新时间:2022-02-27 22:41:41

如果你需要根据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'