Skip to content

Instantly share code, notes, and snippets.

@baybatu
Last active August 9, 2018 10:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baybatu/0c94bec3e8804eb2ff6ed3ce6140a4b0 to your computer and use it in GitHub Desktop.
Save baybatu/0c94bec3e8804eb2ff6ed3ce6140a4b0 to your computer and use it in GitHub Desktop.
Update rows using sub select query in PostgreSQL
UPDATE cars
SET model = subNewCarsTable.newModelName
FROM (SELECT
nc.id AS carId,
nc.model AS newModelName
FROM new_cars nc
WHERE year=2018) subNewCarsTable
WHERE subNewCarsTable.carId = cars.id;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment