Quantcast
Channel: How to do an update + join in PostgreSQL? - Stack Overflow
Viewing all articles
Browse latest Browse all 19

Answer by Nate Smith for How to do an update + join in PostgreSQL?

$
0
0

For those wanting to do a JOIN that updates ONLY the rows your join returns use:

UPDATE aSET price = b_alias.unit_priceFROM      a AS a_aliasLEFT JOIN b AS b_alias ON a_alias.b_fk = b_alias.idWHERE a_alias.unit_name LIKE 'some_value'AND a.id = a_alias.id--the below line is critical for updating ONLY joined rowsAND a.pk_id = a_alias.pk_id;

This was mentioned above but only through a comment..Since it's critical to getting the correct result posting NEW answer that Works


Viewing all articles
Browse latest Browse all 19

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>