The update query with condition?

0 like 0 dislike
7 views
Good day!


People kind prompt as it is possible in mysql update query with a condition to write?

For example, if in box 1, then model it with 2, if 2 is replaced by its 1.


The field has the letter "b" and "empty," so let's say I need to swap, ie, the letter b is replaced by "empty" and "empty" is replaced by "b".
by | 7 views

4 Answers

0 like 0 dislike
UPDATE test SET t = IF(t="a","b","a") WHERE t IN ("a","b");
by
0 like 0 dislike
I would change in three queries via a third value, which is definitely not in this column.
\rUpdate table set field='c' where field=";
Update table set field=" where field='b';
Update table set field='b' where field='c';
by
0 like 0 dislike
if it is bad — there is an old trick:
where 3 = 2+1, 2, and 1 of your options that need to be swapped.
\r
update set field = 3 — field where field in (2,1)
by
0 like 0 dislike
Of course, I write in Oracle SQL, not MySQL, but is there no construction of the type of case or decode, pozwalamy to different values depending on the argument? Three update for the sake of one's actions is a pretty wasteful, Noe?
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
6 answers
asked Mar 21, 2019 by zorba_buddha
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
3 answers
110,608 questions
257,186 answers
0 comments
28,783 users