I need to combine two sql update requests into one

UPDATE test SET text = 'ok' WHERE id = '1' UPDATE test SET text = 'no' WHERE id = '2' 

I tried this:

 UPDATE test SET text = 'ok' WHERE id = '1'; UPDATE test SET text = 'no' WHERE id = '2' 

but does not work. Help me please.

  • CASE try. - BuilderC
  • or union between requests - Gorets
  • one
    union does not work - polstyanko

3 answers 3

 UPDATE test SET text = CASE WHEN id = 1 THEN 'ok' WHEN id = 2 THEN 'no' ELSE text END 
  • Naughty's: CASE has already been proposed - BuilderC
  • Well, the answer is UNION 'th. - Smash
  • @BuilderC, no response was suggested with the union option. Answers are answers, everything else is in the comments. - ReinRaus
 update test join (select 1 a, 'ok' b union all select 2,'no') x on test.id=xa set text=b; 

    I need to combine two sql update requests into one

    Not necessary.
    No need to merge requests without a serious reason.
    In this case, there is not a single reason - both requests will work perfectly separately.

    If there was a need to lock the string, then, firstly, it is not here, and secondly, there is no problem to do with the lock, two queries.

    That is why, when asking a question, you should always voice the real problem, and not your handicraft attempts to solve it.