我有3个表t1,t2和t3.
t1有2列 – > id1,val1
t1有2列 – > id1,val1
t2 -> id2,val2 t3 -> id3,val3 If id1=id2 and id2 = id3
然后我需要更新val1 ad val3.
但我重复id1,每个都应该有相同的val3
我在用
update t1 inner join t2 on t1.id1 = t2.id2 inner join t3 on t2.id2 = t3.id3 set t1.val1 = t3.val3 ;
但是不能这样做.
正确的语法是:
原文链接:/postgresql/238875.htmlUPDATE table_name SET column = { expression | DEFAULT } [,…]
[ FROM fromlist ]
[ WHERE condition ]
所以你的UPDATE语句应该如下所示:
update t1 set val1 = val3 from t2 inner join t3 on t2.id2 = t3.id3 where t1.id1 = t2.id2 ;