Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

MySQL NOT operator

NOT operator

MySQL NOT operator reverses or negates the input.

Syntax:

NOT, !

The operator returns 1 if the operand is 0 and returns 0 if the operand is nonzero. It returns NULL if the operand is NOT NULL.

MySQL Version: 5.6

Example: MySQL NOT operator

In the following MySQL statement, NOT operator negates the input 10, it returns 0.

Code:

SELECT ! 10;

Output:

Example of MySQL NOT operator with zero input

In the following MySQL statement, NOT operator negates the input 0, it returns 1.

SELECT ! 0;

Sample Output:

MySQL> SELECT ! 10;
+------+
| ! 10 |
+------+
|    0 | 
+------+
1 row in set (0.00 sec)

Example of MySQL NOT operator with zero input

In the following MySQL statement, NOT operator negates the input 0, it returns 1.

Sample Output:

MySQL> SELECT ! 0;
+-----+
| ! 0 |
+-----+
|   1 | 
+-----+
1 row in set (0.00 sec)

Example of MySQL NOT operator with NULL

In the following MySQL statement, NOT operator negates the input NULL, it returns NULL.

SELECT ! NULL;

Sample Output:

 MySQL> SELECT ! NULL;
+--------+
| ! NULL |
+--------+
|   NULL | 
+--------+
1 row in set (0.00 sec)
 

Example of MySQL NOT operator with non-zero input

In the following MySQL statement, NOT operator negates the input (10+10), it returns 0.

SELECT ! (10+10);

Sample Output:

 MySQL> SELECT ! (10+10);
+-----------+
| ! (10+10) |
+-----------+
|         0 | 
+-----------+
1 row in set (0.00 sec)
 

Previous: AND operator
Next: OR operator