mysql update query with inner join

后端 未结 2 1697
逝去的感伤
逝去的感伤 2021-01-23 01:48

I have two tables customer and order. I want to update different values in both tables with one query. For example customer table has a city column and value is germany and orde

2条回答
  •  再見小時候
    2021-01-23 02:36

    MySQL supports this operation:

    UPDATE customer c INNER JOIN
           order o
           ON c.cust_id = o.cust_id
        SET c.cust_city = 'Lahore',
            o.order_status = 'Resolved'
        WHERE c.cust_id = 2 ;
    

    Note: order is a really bad name for a table, because it is a SQL keyword. Choose names for things that do not need to be escaped.

提交回复
热议问题