我有 3 个表,我想用 table2< 中的信息(
。 status
列)更新 table1
(status
列)/table1
和 table2
之间的链接在表 table_con
http://www.sqlfiddle.com/#!15/6ce460/4
我想到了一个join
并使用join
的结果来更新table1
select t1.status as t1status,t2.status as t2status,t1.p_id as t1pid, t2.x_id as t2xid
from table1 t1
JOIN table_con tc
ON t1.p_id = tc.p_id
JOIN table2 t2
ON t2.x_id = tc.x_id;
join
目前有效,但我不知道如何继续,
并且查询应该在 psql 中工作。谢谢
最佳答案
在 Postgres 中,您可以在 update
语句中表达连接:
update table1 t1
set ?? = ??
from table_con tc join
table2 t2
on t2.x_id = tc.x_id
where t1.p_id = tc.p_id;
在 set
列中填写您要设置的列和值。
关于sql - PostgreSQL 在 3 个表上使用 JOIN 更新列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36463141/