Created
March 27, 2019 04:31
-
-
Save peacefixation/1da867686ff4c1ede930c51752e757be to your computer and use it in GitHub Desktop.
Postgres update join
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- given two tables with a foreign key | |
-- and the requirement to set a field in tableA to the value of the corresponding field in tableB | |
-- in this case setting tableA.someField to tableB.someOtherField where tableA.fk_id = tableB.id | |
-- tableA ( | |
-- id | |
-- someField | |
-- fk_id | |
-- ) | |
-- tableB ( | |
-- id | |
-- someOtherField | |
-- ) | |
UPDATE tableA | |
SET someField = tableB.someOtherField | |
FROM tableB | |
WHERE tableA.fk_id = tableB.id; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment