Update and left outer join statements

前端 未结 5 937
被撕碎了的回忆
被撕碎了的回忆 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条回答
  •  渐次进展
    2021-02-06 23:59

    Update t 
    SET 
           t.Column1=100
    FROM 
           myTableA t 
    LEFT JOIN 
           myTableB t2 
    ON 
           t2.ID=t.ID
    

    Replace myTableA with your table name and replace Column1 with your column name.

    After this simply LEFT JOIN to tableB. t in this case is just an alias for myTableA. t2 is an alias for your joined table, in my example that is myTableB. If you don't like using t or t2 use any alias name you prefer - it doesn't matter - I just happen to like using those.

提交回复
热议问题