How to do 3 table JOIN in UPDATE query?

Ricky picture Ricky · Mar 4, 2013 · Viewed 471.4k times · Source

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.column_c = a.column_c + 1

Now I am looking to do this if there are 3 tables involved something like this.

    UPDATE tableC c JOIN tableB b JOIN tableA a

my question is basically... is this possible to do 3 table join on an UPDATE statement? and what is the correct syntax for it? Thank you. Do i do the...

 JOIN tableB, tableA
 JOIN tableB JOIN tableA

Answer

echo_Me picture echo_Me · Mar 4, 2013

the answer is yes you can

try it like that

UPDATE TABLE_A a 
    JOIN TABLE_B b ON a.join_col = b.join_col AND a.column_a = b.column_b 
    JOIN TABLE_C c ON [condition]
SET a.column_c = a.column_c + 1

EDIT:

For general Update join :

   UPDATE TABLEA a 
   JOIN TABLEB b ON a.join_colA = b.join_colB  
   SET a.columnToUpdate = [something]