I'm getting some weird results, so I need to just check myself...
SELECT * FROM table WHERE complete != 0 AND pending != 1
To be clear, these are allowed:
pending = 0, complete = 0 pending = 1, complete = 1 pending = 0, complete = 1
THis is NOT allowed to be returned from my query:
pending = 1, complete = 0
What am I missing here...?
In MySQL, you can use the <> or != operators to test for inequality in a query. For example, we could test for inequality using the <> operator, as follows: SELECT * FROM contacts WHERE last_name <> 'Johnson';
MySQL Not Equal is an inequality operator that used for returning a set of rows after comparing two expressions that are not equal. The MySQL contains two types of Not Equal operator, which are (< >) and (! =).
If != and <> both are the same, which one should be used in SQL queries? Here is the answer – You can use either != or <> both in your queries as both technically same but I prefer to use <> as that is SQL-92 standard.
The symbol <> in MySQL is same as not equal to operator (!=). Both gives the result in boolean or tinyint(1). If the condition becomes true, then the result will be 1 otherwise 0. Case 1 − Using !=
Try:
SELECT * FROM table WHERE NOT (complete = 0 AND pending = 1)
or
SELECT * FROM table WHERE !(complete = 0 AND pending = 1)
EDIT: I went and looked at: http://dev.mysql.com/doc/refman/4.1/en/expressions.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With