I'm trying to update desiredValue from updatedTable table if only the statements from where clause is satisfied, otherwise it should not set a value. Is below a correct statement?

 update updatedTable si  
 set desiredValue = select desiredValue
                    from otherTable sl 
                    where sl.att1 = si.att1 and sl.att2 = si.att2;
New contributor
Yalin Eren Deliorman is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Try like below:

UPDATE updatedTable
set updatedTable.desiredValue = otherTable.desiredValue
FROM otherTable
WHERE updatedTable.att1 = otherTable.att1 and updatedTable.att2 = otherTable.att2

Your Answer

Yalin Eren Deliorman is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.