I have a table like this:
// Answers
+----+---------+-----------------+-------------+
| id | answer | accepted-answer | question_id |
+----+---------+-----------------+-------------+
| 1 | answer1 | null | 1 |
| 2 | answer2 | 1 | 1 |
| 3 | answer3 | null | 1 |
+----+---------+-----------------+-------------+
Now I'm trying to change accepted-answer
. I want this output:
+----+---------+-----------------+-------------+
| id | answer | accepted-answer | question_id |
+----+---------+-----------------+-------------+
| 1 | answer1 | null | 1 |
| 2 | answer2 | null | 1 |
| 3 | answer3 | 1 | 1 |
+----+---------+-----------------+-------------+
Note: I just have the new id (the id of new accepted answer, not old one) which is $id=3
in the example above. I also have question_id
which is $question_id=1
in the example above.
I can do that by two separated queries like these:
UPDATE Answers SET accepted_answer = null WHERE question_id = :question_id;
And
UPDATE Answers SET accepted_answer = 1 WHERE id = :id;
Now I want to know, can I do that in the same time and in one query?