MySQL query does NOT check multiple values

Is there a better way to write the following "where" part of a mysql query:

WHERE t.status IS NOT 'resolved'
  AND t.status IS NOT 'closed'
  AND t.status IS NOT 'deleted'

can they be combined into a single expression where?

+5
source share
2 answers
WHERE t.status NOT IN ('resolved', 'closed', 'deleted')

Boolean algebra says that these two expressions are equivalent:

NOT A AND NOT B AND NOT C

NOT (A OR B OR C)

This is DeMorgan Law .

+9
source

In most cases, you need to consider the issue of cost before trying to combine them into something more readable and smarter. Check your explanation plan or equivalent for MySQL if this change leads to an increase in value.

+2
source

All Articles