MySQL update a joined table

后端 未结 4 1504
感动是毒
感动是毒 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 06:05

    Another correct construction, which we can use in this situation:

    UPDATE T1, T2,
    [INNER JOIN | LEFT JOIN] T1 ON T1.C1 = T2. C1
    SET T1.C2 = T2.C2, 
        T2.C3 = expr
    WHERE condition
    

    The above example is take from: MySQL UPDATE JOIN.

    Reaching for the MySQL 8.0 Reference Manual we will find such a description of multiple-table UPDATE syntax:

    UPDATE [LOW_PRIORITY] [IGNORE] table_references
    SET assignment_list
    [WHERE where_condition]
    

    The table_references clause lists the tables involved in the join.

    So multiple-table MySQL's syntax doesn't support FROM, ORDER BY or LIMIT clauses as opposed to single-table syntax.

提交回复
热议问题