MySQL NOT Operator

MySQL NOT Operator is one of the Logical Operators that is useful in the WHERE Clause to apply filters on the rows returned by SELECT Statement. This operator returns the result as follows.

  • 1, if the operand is zero
  • 0, if the operand is 1.
  • NULL, If the operand is NULL.

To explain the Logical NOT operator in the MySQL WHERE Clause to filter the data, we are going to use the customer table mentioned in the MySQL AND article.

MySQL NOT Operator Command prompt

In this MySQL example, we pass Zeros, Ones, and Null values with a different combination. This example helps you to understand the Truth table behind the NOT Operator.

SELECT NOT 1;

SELECT NOT 0;

SELECT NOT NULL;

SELECT !1;

SELECT !(1 - 1);

OUTPUT

+-------+-------+----------+----+----------+
| NOT 1 | NOT 0 | NOT NULL | !1 | !(1 - 1) |
+-------+-------+----------+----+----------+
|     0 |     1 |     NULL |  0 |        1 |
+-------+-------+----------+----+----------+

NOT Example

The NOT Operator is used to test user specified conditions in the WHERE Clause against the SELECT Statement records. Refer to the MySQL SELECT Statement.

USE company;
SELECT CustID,
		First_Name, Last_Name,
        Education, Profession,
        Yearly_Income, Sales
FROM customers
WHERE Education != 'High School';
NOT Operator Example

TIP: Please refer to the MySQL NOT LIKE and MySQL IS operator articles.