Home > Mobile >  Postgres, Need help updating only NULL values
Postgres, Need help updating only NULL values

Time:06-19

I have two tables 'A', 'B'. I want to write a query that accomplishes the results shown below.

enter image description here

currently I have this statement

UPDATE A
SET version = (
   SELECT B.version
   FROM B 
   WHERE B.id = A.id 
)

It works, but it updates ALL the rows, how can I write it so that only the null values are updated ?

CodePudding user response:

UPDATE A SET version = ( SELECT B.version FROM B WHERE B.id = A.id ) where A.version is null

  • Related