D
D
Daniil Sukhikh2021-03-04 15:22:28
SQL
Daniil Sukhikh, 2021-03-04 15:22:28

How to execute two updates in one, with different conditions?

I have a table and it has a default column, I need a query like this: update the row with the value default = 1 by replacing default with 0 and replace the row with the value id = any number by replacing it with default = 1.
How to do this in one query ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Slava Rozhnev, 2021-03-04
@danchikraw

Something like this:

UPDATE tbl 
SET default = CASE
    WHEN id = любое число THEN 1
    WHEN default = 1 THEN 0
    ELSE default
END;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question