Stack Stack - 1 year ago 55
MySQL Question

How can I make a condition opposite in MySQL?

I have this query:

->prepare("UPDATE users
SET reputation = reputation +
WHEN id = ? THEN 2
WHEN id = ? AND ? THEN 15
WHERE id IN (?, ?); ")
->execute(array($author_ques_id, $author_ans_id, $bool, $author_ans_id, $author_ques_id));

Please focus on this condition:

WHEN id = ? AND ? THEN 15
// ^ this is containing a boolean value

And I want to opposite the value of that condition. I mean I want to run that condition when
and don't run it when it is

I can do that before passing by php:

$bool = !$bool;

But I want to know can I do that in the query by MySQL?

Answer Source

Use NOT:

... AND NOT ? THEN 15
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download