SQL NOT Operator
What is the NOT Operator?
The NOT operator is used to negate a condition, providing the opposite or negative result. It can be combined with various comparison or logical operators.
Example: Negating a Condition
Select all customers that are NOT from Spain:
SELECT *
FROM Customers
WHERE NOT Country = 'Spain';
Syntax
SELECT column1, column2, ...
FROM table_name
WHERE NOT condition;
Using NOT with Different Operators
NOT LIKE
Select customers whose names do not start with the letter ‘A’:
SELECT *
FROM Customers
WHERE CustomerName NOT LIKE 'A%';
NOT BETWEEN
Select customers whose CustomerID is not between 10 and 60:
SELECT *
FROM Customers
WHERE CustomerID NOT BETWEEN 10 AND 60;
NOT IN
Select customers who are not from Paris or London:
SELECT *
FROM Customers
WHERE City NOT IN ('Paris', 'London');
NOT Greater Than
Select customers whose CustomerID is not greater than 50:
SELECT *
FROM Customers
WHERE NOT CustomerID > 50;
NOT Less Than
Select customers whose CustomerID is not less than 50:
SELECT *
FROM Customers
WHERE NOT CustomerID < 50;
