2016-04-06 71 views
0

我有3個表,我想更新table1(列status)與table2信息(列status)。 table1table2之間的聯繫是在表table_conPostgreSQL更新列與加入3個表

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中工作。感謝

+0

要更新哪些列? –

回答

1

在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; 

填寫你Wnt信號設置列和價值set列。

+0

太棒了,那有效。只是一個;太多了。非常感謝。 – fabvys