LeoSam LeoSam - 1 year ago 85
MySQL Question

mysql update column with value from another table

I have two tables, both looking like

id name value
===================
1 Joe 22
2 Derk 30


I need to copy the value of
value
from
tableA
to
tableB
based on check name in each table.

Any tips for this
UPDATE
statement?

Answer Source

In addition to this answer if you need to change t1.value according to t2.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'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download