Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL query IS NOT test against multiple values

Tags:

mysql

Is there a better way to write the following 'where' portion 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 where statement?

like image 628
Aaron Murray Avatar asked Sep 19 '11 06:09

Aaron Murray


1 Answers

WHERE t.status NOT IN ('resolved', 'closed', 'deleted')

Boolean algebra says these two expressions are equivalent:

NOT A AND NOT B AND NOT C

NOT (A OR B OR C)

This is DeMorgan's Law.

like image 190
Bill Karwin Avatar answered Nov 14 '22 21:11

Bill Karwin