Coding⏱️ 2 min read📅 2026-06-03

How to Fix: How to do an update + join in PostgreSQL?

Update and join in PostgreSQL

Quick Answer: Use the `JOIN` clause before the `UPDATE` statement, like this: `UPDATE vehicles_vehicle v JOIN shipments_shipment s ON v.shipment_id = s.id SET v.price = s.price_per_vehicle;

To update a table in PostgreSQL while joining another table, you need to use the `UPDATE` statement with a subquery that includes an `INNER JOIN`. The syntax for this is as follows:

🛑 Correct Syntax

  • The correct syntax is: `UPDATE vehicles_vehicle v SET v.price = (SELECT price_per_vehicle FROM shipments_shipment s WHERE s.id = v.shipment_id);`

🚀 How to Resolve This Issue

Method 1: Using a Subquery

  1. Step 1: Replace the `JOIN` clause with an `INNER JOIN` subquery that selects the required column (`price_per_vehicle`) from the joined table.

✨ Wrapping Up

In PostgreSQL, using a subquery to update a table while joining another table is a common and effective solution. By following the correct syntax and method, you can efficiently update your data while maintaining data integrity.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions