NOT Operator Example
Lets look at some examples of NOT operator in SQL and understand it’s working.
The following SQL statement selects all fields from “Customers” where the country is not “UK” SELECT * FROM Customers WHERE NOT Country=’UK’;
Customer ID | Customer Name | City | PostalCode | Country |
---|---|---|---|---|
1 | John Wick | New York | 1248 | USA |
3 | Rohan | New Delhi | 100084 | India |
Combining AND, OR and NOT
You can also combine the AND, OR, and NOT operators. Example: 1.) SELECT * FROM Customers WHERE NOT Country=’USA’ AND NOT Country=’UK’;
Customer ID | Customer Name | City | PostalCode | Country |
---|---|---|---|---|
3 | Rohan | New Delhi | 100084 | India |
Alternatively you can use <> ( Not Operator) to get the desired result
SELECT * FROM Customer WHERE Country <>'USA';
Output:
SQL NOT Operator
SQL NOT Operator is used to return the opposite result or negative result. It is a logical operator in SQL, that negates the boolean expression in the WHERE clause.
It is mostly used to specify what should not be included in the results table.
Contact Us