I've got two tables, a
and b
, both with product_name
and value
. The value column in a
is null.
I'd like to update the a
table with values from the b
table. Because of a quirk in the data, product_name
is not unique in either table.
I only want to set the value when there is one unambiguous match on product_name
between the two. When more than one row in a
has the same product name, or more than one row matches from b
, I'd like to keep the value empty. Is there an efficient way to do this in Postgres?
A simpler version of this would be to first identify unique product names in a
. Then, update rows where only a single row in b
matches -- but I'm also not sure how to write that constraint.