I have two tables, and want to update fields in T1 for all rows in a LEFT JOIN.
For an easy example, update all rows of the following result-set:
SELECT T1.* FROM T1 LEFT JOIN T2 ON T1.id = T2.id WHERE T2.id IS NULL
The MySQL manual states that:
Multiple-table UPDATE statements can use any type of join allowed in SELECT statements, such as LEFT JOIN.
But I cannot find the proper syntax for doing that in the documented multiple-tables UPDATE.
What is the proper syntax?
Note that for a
SELECTit would be more efficient to useNOT IN/NOT EXISTSsyntax:See the article in my blog for performance details:
LEFT JOINcompared toNOT INUnfortunately,
MySQLdoes not allow using the target table in a subquery in anUPDATEstatement, that’s why you’ll need to stick to less efficientLEFT JOINsyntax.