带子查询的Postgresql更新

时间:2013-07-11 04:14:15

标签: postgresql

UPDATE Customer C
SET name = B.name, 
age = B.age
FROM (SELECT A.*, B.* FROM CUSTOMER_TEMP WHERE A.ID = B.ID) AS B

我得到了一个如上所述的sql,在运行查询后,它将我的所有行更新为相同的结果。

我想知道我需要在

之后的地方
UPDATE Customer C
SET name = B.name, 
age = B.age
FROM (SELECT A.*, B.* FROM CUSTOMER_TEMP WHERE A.ID = B.ID) AS D
WHERE C.ID = D.ID

但我得到的这个id对于最后一次查询是不明确的。

1 个答案:

答案 0 :(得分:0)

试试这个

update Customer set
    name = B.name, 
    age = B.age
from Customer as C
    inner join CUSTOMER_TEMP as B on B.ID = C.ID

SQL FIDDLE EXAMPLE