Open In App
Related Articles

SQL | NOT Operator

Improve Article
Improve
Save Article
Save
Like Article
Like

NOT Syntax SELECT column1, colomn2, … FROM table_name WHERE NOT condition; Demo Database Below is a selection from the “Customers” table in the Northwind sample database:

Customer IDCustomer NameCityPostalCodeCountry
1John WickNew York1248USA
2Around the HornLondonWA1 1DPUK
3RohanNew Delhi100084India

NOT Example The following SQL statement selects all fields from “Customers” where country is not “UK” SELECT * FROM Customers WHERE NOT Country=’UK’;

Customer IDCustomer NameCityPostalCodeCountry
1John WickNew York1248USA
3RohanNew Delhi100084India

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 IDCustomer NameCityPostalCodeCountry
3RohanNew Delhi100084India

Alternatively you can use <> ( Not Operator) to get the desired result :-

SELECT * FROM Customer WHERE Country <>'USA';

Output :-

 

Last Updated : 24 Mar, 2023
Like Article
Save Article
Similar Reads