I am trying to join three tables within an update statement, but I have been unsuccessful so far. I know this query works for joining two tables:
update table 1
set x = X * Y
from table 1 as t1 join table 2 as t2 on t1.column1 = t2.column1
However, in my case, I need to join three tables so:
update table 1
set x = X * Y
from table 1 as t1 join table 2 as t2 join table3 as t3
on t1.column1 = t2.column1 and t2.cloumn2 = t3.column1
Will not work. I also tried the following query:
update table 1
set x = X * Y
from table 1, table 2, table 3
where column1 = column2 and column2= column3
Does anyone know of a method to accomplish this?
You definitely don’t want to use
table, table, tablesyntax; here’s why. As for your middle code sample, join syntax follows roughly the same rules forSELECTas it does forUPDATE.JOIN t2 JOIN t3 ON ...is not valid, butJOIN t2 ON ... JOIN t3 ONis valid.So here is my proposal, though it should be updated to fully qualify where
ycomes from: