Instantly share code, notes, and snippets.

Embed
What would you like to do?
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