Answer the question
In order to leave comments, you need to log in
Mutual replacement in SQL?
The table of postings provodka is given.
It is known that in this table there are postings only with the code 20501 and 20502.
How to replace 20501 in all lines with 20502, and 20502 with 20501.
How to replace, for example, 20501 with 20502, I understand. REPLACE(Code, 20501, 20502). It is not possible to replace sequentially, because after the first replacement, the value 20502 remains in all rows.
Answer the question
In order to leave comments, you need to log in
Replace the first one with the third one.
Replace the second with the first.
Replace the third with the second.
L - logic
If you are bored in other ways.
https://tproger.ru/problems/popular-ways-to-swap/
Why can't you use the solution?
The table is traversed only once.
UPDATE provodka p
SET p.code = CASE
when p.code = 20501 then 20502
when p.code = 20502 then 20501
else p.code
END
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question