PostgreSQL Cheat Sheet/Update from another table

Update rows using another table in the same statement.

Section: Insert, Update, Delete, and Merge

Update from another table

sql
sql
UPDATE orders o
SET customer_tier = c.tier
FROM customers c
WHERE o.customer_id = c.customer_id;
Explanation

See summary for usage details.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Insert, Update, Delete, and Merge
Update rows
Modify matching rows.
OpenIn sheetsqlsame section
Insert row
Insert one row into a table.
OpenIn sheetsqlsame section
Insert multiple rows
Insert many rows in one statement.
OpenIn sheetsqlsame section
Insert with RETURNING
Insert rows and immediately return generated values.
OpenIn sheetsqlsame section
Upsert with ON CONFLICT
Handle unique conflicts by updating instead of failing.
OpenIn sheetsqlsame section
Delete rows
Delete matching rows.
OpenIn sheetsqlsame section