2013-07-11 112 views
0
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如上,我運行查詢後,它將我所有的行更新爲相同的結果。Postgresql更新與子查詢

我不知道我需要

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是模糊的最後查詢。

回答

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