PostgreSQL 在 update 時的 join 問題

edited 十月 2013 in 資料庫
很直覺的打了這樣的 SQL:
UPDATE cards AS c
INNER JOIN organizations AS o ON o.id = c.organization_id
SET c.organization_scope = o.parent_id;

最後發現得改成這樣才能運作:
UPDATE cards AS c
SET organization_scope = o.parent_id
FROM organizations AS o
WHERE o.id = c.organization_id;

甚至這樣也會錯:
UPDATE cards AS c
SET c.organization_scope = o.parent_id
FROM organizations AS o
WHERE o.id = c.organization_id;

說真的,我對 ANSI SQL 標準沒什麼研究,所以不知道哪種語法比較正確,但是在 MySQL 好像沒有這麼多限制 XD

原始討論: http://twpug.net/x/modules/newbb/viewtopic.php?topic_id=5446

評論

Sign In or Register to comment.