How to do 3 table JOIN in UPDATE query?

后端 未结 6 2045
走了就别回头了
走了就别回头了 2020-11-21 07:00

I asked a question and got this reply which helped.

   UPDATE TABLE_A a JOIN TABLE_B b 
   ON a.join_col = b.join_col AND a.column_a = b.column_b 
   SET a.c         


        
6条回答
  •  终归单人心
    2020-11-21 07:59

    An alternative General Plan, which I'm only adding as an independent Answer because the blasted "comment on an answer" won't take newlines without posting the entire edit, even though it isn't finished yet.

    UPDATE table A
    JOIN table B ON {join fields}
    JOIN table C ON {join fields}
    JOIN {as many tables as you need}
    SET A.column = {expression}
    

    Example:

    UPDATE person P
    JOIN address A ON P.home_address_id = A.id
    JOIN city C ON A.city_id = C.id
    SET P.home_zip = C.zipcode;
    

提交回复
热议问题