update from another table mysql code example

Example 1: mysql UPDate with enner join

UPDATE T1, T2,
[INNER JOIN | LEFT JOIN] T1 ON T1.C1 = T2. C1
SET T1.C2 = T2.C2, 
    T2.C3 = expr
WHERE condition

Example 2: update table from another table mysql

UPDATE t1
SET t1.COL1 = t2.COL1, t1.COL2 = t2.COL2
FROM my_table AS t1
INNER JOIN my_other_table AS t2 ON t1.COLID = t2.ID
WHERE t1.COL3 = 'OK';

Example 3: mysql update table from another table

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'

Example 4: mysql update table from select on another table

UPDATE TableB 
SET TableB.value = (
    SELECT TableA.value 
    FROM TableA
    WHERE TableA.name = TableB.name
);

Tags:

Sql Example