mysql update from another table code example
Example 1: update left join mysql
UPDATE t1
LEFT JOIN
t2
ON t2.id = t1.id
SET t1.col1 = newvalue
WHERE t2.id IS NULL
Example 2: 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 3: 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 4: 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 5: mysql update table from select on another table
UPDATE TableB
SET TableB.value = (
SELECT TableA.value
FROM TableA
WHERE TableA.name = TableB.name
);
Example 6: mysql select update same table
UPDATE
products_description pd INNER JOIN products_description pd2 ON
(pd.products_id=pd2.products_id AND pd2.language_id=1 AND pd.language_id<>1)
SET pd.products_seo = pd2.products_seo;