How to Do an Update With Join in PostgreSQL?

When you need to find the row you want to update with a join statement, you can use join statement as same as select statements in PostgreSQL.

TL;DR: UPDATE orders AS v SET price = s.price_per_product FROM products AS s WHERE v.product_id = s.id;

In update statements you can use from and join statement as same as select statements.

Use case for Update with Join

Asynchronous tasks are the best use case for that kind of approach.

A software might insert orders to a database, in background, an asynchronous tool can update their status, costs etc.

A new post everyday, subscribe now and don’t miss it!

Subscribe to our newsletter for cool news

Hi! I’m an IT Specialist

I want to hear from you! I am Working with enterprises for 10+ years to improve their infrastructure and efficiency.

Get in touch with me.

Leave a Reply

Discover more from Empower. Innovate. Transform.

Subscribe now to keep reading and get access to the full archive.

Continue reading