SQL NOT Operator
The NOT operator is used in combination with other operators to give the opposite or negative result.
In the below statement we want to return all employee that are NOT from India:
Example
Select only the employee that are NOT from India:You can click on above box to edit the code and run again.
SELECT * FROM employee WHERE NOT Country = 'India' ;
Output
Syntax
SELECT column1, column2, ... FROM table_name
WHERE NOT condition;
Demo Employee table
This employee table is used for examples:
NOT LIKE
Example
Select employee that does not start with the letter 'R':You can click on above box to edit the code and run again.
SELECT * FROM employee WHERE Employee_name NOT LIKE 'R%' ;
Output
NOT BETWEEN
Example
Select employee with a Employee id not between 7 and 12:You can click on above box to edit the code and run again.
SELECT * FROM employee WHERE Employee_id NOT BETWEEN 7 AND 12 ;
Output
NOT Greater Than
Example
Select employee with a Employee id not greater than 8:You can click on above box to edit the code and run again.
SELECT * FROM employee WHERE NOT Employee_id > 8 ;
Output
Note: There is a not-greater-then operator: !> that would give you the same result.
NOT Less Than
Example
Select employee with a Employee id not less than 8:You can click on above box to edit the code and run again.
SELECT * FROM employee
WHERE NOT Employee_id < 8 ;
Output
Note: There is a not-less-then operator: !< that would give you the same result.