MySQL update a joined table

后端 未结 4 1508
感动是毒
感动是毒 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条回答
  •  旧时难觅i
    2020-11-28 06:07

    You have the ordering of the statements wrong. You can read up on the syntax here (I know, it's pretty hard to read.

    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;
    

    sql fiddle

提交回复
热议问题