I have a table of real estate data with lots of NULLS in address column. I want to replace these nulls based on the unique ID. (I'm following Alex the Analyst tutorial). However when I use this in postgresql, I'm getting an error:
ERROR: relation "a" does not exist
UPDATE a SET
propertyaddress = COALESCE(a.propertyaddress, b.propertyaddress)
FROM nashville_housing_data a
JOIN nashville_housing_data b
ON a.parcelid = b.parcelid
AND a.uniqueid <> b.uniqueid
WHERE propertyaddress is null
Now, when I replaced a with the table name, it updated all address rows to one specific address.
You can't UPDATE aliases; you must use the table name.
Also,
COALESCEis useless here because the conditionWHERE propertyaddress is nullguarantees the first term is always null, so just assignb.propertyaddress.Try this:
If there can be more than one other rows with a matching parcelid, break the tie with MAX():