L
L
leni_m2018-03-26 16:11:30
MySQL
leni_m, 2018-03-26 16:11:30

Is it possible to write one request?

There is a table with fields id and active (0 or 1).
Only one row can have active=1.
So here's the task: to make the selected row active by its id.
I can make two requests:
1. make active 0, where it was 1 (Update table SET active=0 WHERE active=1)
2. make active 1, where our id is. (Update table SET active=1 WHERE id=:id)
Is it possible to somehow combine them into one?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lazy @BojackHorseman MySQL, 2018-03-26
@leni_m

set fieldname = case when id=:id then 1 else 0 end

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question