MySQL update a joined table

The multi-table UPDATE syntax in MySQL is different from Microsoft SQL Server. You don’t need to say which table(s) you’re updating, that’s implicit in your SET clause.

UPDATE tableA a
JOIN tableB b
   ON a.a_id = b.a_id
JOIN tableC c
   ON b.b_id = c.b_id
SET b.val = a.val+c.val
WHERE a.val > 10
    AND c.val > 10;

There is no FROM clause in MySQL’s syntax.

UPDATE with JOIN is not standard SQL, and both MySQL and Microsoft SQL Server have implemented their own ideas as an extension to standard syntax.

Leave a Comment