How can I do an update so that it updates several values, my query is
UPDATE ACL_FAC SET ID_CARGA =
(SELECT SEQUENCIA FROM ACL_FAC WHERE ID_CARGA IN (4005946,
4005947,
4005948,
4005949,
4005950)AND SEQUENCIA IN(680456522,
680482070,
680561046,
680561049,
680562329)
)
WHERE ID_CARGA IN (4005946,
4005947,
4005948,
4005949,
4005950)AND SEQUENCIA IN(680456522,
680482070,
680561046,
680561049,
680562329)
what I want to do is update the ID_CARGA field placing the value that has SEQUENCE but this is for several values, with one value if possible but with several values as the example generates an error
The subquery returned more than one value, which is not correct when followed by =, !=, <, <=, >, >= or when used as an expression.
The direct option is:
Personally, I prefer to know what the result will be before doing the update and then apply it. For this I always use a common expression table. And with the output of this I cross it with the source table and see what I am going to do. Something like:
If the result obtained is as expected, then I comment the code of the select and I keep the update. If the set is complex, instead of directly updating the cte I perform an inner join against the table to be updated (in this case it is not necessary).
If you have never used common expression tables it may help you to read this: Cte