Martin AJ
Martin AJ

Reputation: 6697

How can I make a condition opposite in MySQL?

I have this query:

$db
->prepare("UPDATE users 
            SET reputation = reputation + 
                             CASE
                               WHEN id = ? THEN 2
                               WHEN id = ? AND ? THEN 15
                             END
            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 $bool is false and don't run it when it is true.

I can do that before passing by php:

$bool = !$bool;

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

Upvotes: 0

Views: 126

Answers (2)

fpierrat
fpierrat

Reputation: 804

Maybe you mean
... AND ? IS FALSE or
... AND ? IS NOT TRUE

http://code.openark.org/blog/mysql/syntax-of-the-day-is-true-and-is-false

Upvotes: 1

Thorsten Kettner
Thorsten Kettner

Reputation: 95052

Use NOT:

... AND NOT ? THEN 15

Upvotes: 1

Related Questions