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
- Weekly Trends
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
- JavaScript functions Exercises
- Python Tutorial
- Python Array Exercises
- SQL Cross Join
- C# Sharp Array Exercises
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook