Update and left outer join statements

前端 未结 5 1003
被撕碎了的回忆
被撕碎了的回忆 2021-02-06 23:45

I have two tabels with a relation and I want to update a field in table A. Is it possible to combine update and join in the same query? I googled it but didnt find any working s

5条回答
  •  萌比男神i
    2021-02-07 00:13

    In mysql the SET clause needs to come after the JOIN. Example:

    UPDATE e
        LEFT JOIN a ON a.id = e.aid
        SET e.id = 2
        WHERE  
            e.type = 'user' AND
            a.country = 'US';
    

提交回复
热议问题