Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SQL: 結合して update

結合して update

  • 外部テーブルが一つのときは from で2つめのテーブルを指定する
  • join ではなく where で結合する
UPDATE blog.table_a
SET val = B.val
FROM blog.table_b AS B
WHERE table_a.id = B.id;
  • 外部テーブルが複数の場合は、from の次に join 節を使える
UPDATE blog.table_a
SET val = C.val
FROM blog.table_b AS B
       LEFT OUTER JOIN blog.table_c AS C ON C.id = B.id
WHERE blog.table_a.id = C.id;

PostgreSQLでUPDATE。 | Developers.IO

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment