1

I have written this query to update null values from another column which i have extracted using JOIN however, it shows syntex error and not working.

I would like to populate PropertyAddress values from ifnull(a.propertyaddress,b.propertyaddress) for that i have written this query.

enter image description here

select a.ParcelID,a.PropertyAddress, b.ParcelID,b.PropertyAddress,
ifnull(a.PropertyAddress,b.PropertyAddress)
from housingdata a
join housingdata b
    on a.ParcelID = b.ParcelID
    and a.UniqueID <> b.UniqueID
where a.PropertyAddress is null;


update a 
set PropertyAddress = ifnull(a.PropertyAddress,b.PropertyAddress)
from housingdata a  << getting syntex error here*
join housingdata b
on a.ParcelID = b.ParcelID
and a.UniqueID <> b.UniqueID
where a.PropertyAddress is null;

however it shows an error in from clause in update statement.

1
  • In a select statement, you need to specify what and then which table from, but in an update statement you specify which table is updated first and then what to set in it. The join doesn't really differ, though as pointed out, you might want the join to sit with the main table. where clauses are also identical between them. Commented Feb 16, 2022 at 13:37

1 Answer 1

3

UPDATE ... JOIN syntax in MySQL is different from SQL-Server, you might want to do that, and set PropertyAddress might use right alias because there are two tables holding PropertyAddress from your query.

your logic might set a.PropertyAddress = b.PropertyAddress directly because there is a condition a.PropertyAddress is null.

update housingdata a  
join housingdata b
on a.ParcelID = b.ParcelID
and a.UniqueID <> b.UniqueID 
set a.PropertyAddress = b.PropertyAddress
where a.PropertyAddress is null;
Sign up to request clarification or add additional context in comments.

4 Comments

got error column 'PropertyAddress' in field list is an ambigious' @D-Shih
I edit my answer and add some suggestions.
perfect, worked:) Many thanks.
@alex No problem glad to help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.