MySQL update a joined table

后端 未结 4 1506
感动是毒
感动是毒 2020-11-28 05:49

I want to update a table in a statement that has several joins. While I know the order of joins doesn\'t really matter (unless you you are using optimizer hints) I ordered

4条回答
  •  悲哀的现实
    2020-11-28 05:54

    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.

提交回复
热议问题