PostgreSQL更新列,包含超过3个表的联接
我有3个表,我想用PostgreSQL更新列,包含超过3个表的联接,sql,postgresql,join,sql-update,Sql,Postgresql,Join,Sql Update,我有3个表,我想用表2中的信息(列状态)更新表1(列状态)。table 1和table 2之间的链接位于表table\u con 我考虑了一个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
表2
中的信息(列状态
)更新表1
(列状态
)。table 1
和table 2
之间的链接位于表table\u con
我考虑了一个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 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
列中填写您需要设置的列和值。您想更新哪些列?如果t1必须与tc和t2同时连接怎么办?@AMJ。然后在WHERE
子句中添加另一个条件。