Preamble
The SQL condition NOT (sometimes called the NOT operator) is used to override the condition in the WHERE sentence of the SELECT, INSERT, UPDATE or DELETE operator.
Syntax of NOT condition in SQL
NOT condition_id
Arguments or parameters
- To include an entry in the result set, the opposing condition must be chosen. condition – This is a condition for denial.
Use NOT with IN condition
Let’s begin by looking at how NOT can be used with the IN condition. The NOT IN condition is created when the NOT operator is combined with the IN condition. The expression will be checked to see if it is not on the list.
In this illustration, the product table contains the information below:
| prod_id | prod_name | cat_id |
| 1 | Pear | 50 |
| 2 | Banana | 50 |
| 3 | Orange | 50 |
| 4 | Apple | 50 |
| 5 | Bread | 75 |
| 6 | Sliced Ham | 25 |
| 7 | Kleenex | NULL |
Type the SQL query in the box provided.
SELECT *
FROM prods
WHERE prod_name NOT IN ('Pear', 'Banana', 'Bread');
There will be four entries chosen. You should see the outcomes listed below.
| prod_id | prod_name | cat_id |
| 3 | Orange | 50 |
| 4 | Apple | 50 |
| 6 | Sliced Ham | 25 |
| 7 | Kleenex | NULL |
The products table will be searched for all rows in this example where prod_name does not match Pear, Banana, or Bread. In some cases, it is more effective to list the values you do not want rather than the values you do.
The following SQL statement is equivalent to this.
SELECT *
FROM prods
WHERE prod_name <> 'Pear'
AND prod_name <> 'Banana'
AND prod_name <> 'Bread';
Using NOT with IS NULL condition
When you combine the NOT operator with the IS NULL condition, you create the IS NOT NULL condition which allows you to check a value other than NULL. This is a recommended comparison statement for use in SQL when checking values other than NULL.
Let’s look at an example which shows how to use the IS NOT NULL condition in a query.
Using the same products as in the previous example.
| prod_id | prod_name | cat_id |
| 1 | Pear | 50 |
| 2 | Banana | 50 |
| 3 | Orange | 50 |
| 4 | Apple | 50 |
| 5 | Bread | 75 |
| 6 | Sliced Ham | 25 |
| 7 | Kleenex | NULL |
Enter the following SQL statement.
SELECT *
FROM prods
WHERE cat_id IS NOT NULL;
6 records will be selected. Here are the results that you should get.
| prod_id | prod_name | cat_id |
| 1 | Pear | 50 |
| 2 | Banana | 50 |
| 3 | Orange | 50 |
| 4 | Apple | 50 |
| 5 | Bread | 75 |
| 6 | Sliced Ham | 25 |
In this example, all records from the products table will be returned where customer_id is not NULL.
Using NOT with LIKE condition
Next, let’s look at an example of using the NOT operator with the LIKE condition.
In this illustration, we have a table with the information below:
| suppl_id | suppl_name | city_id | state_id |
| 100 | Yandex | Moscow | Russian |
| 200 | Lansing | Michigan | |
| 300 | Oracle | Redwood City | California |
| 400 | Bing | Redmond | Washington |
| 500 | Yahoo | Sunnyvale | Washington |
| 600 | DuckDuckGo | Paoli | Pennsylvania |
| 700 | Qwant | Paris | France |
| 800 | Menlo Park | California | |
| 900 | Electronic Arts | San Francisco | California |
Let’s look at each entry in the Suppliers table where the letter “o” is absent from Supplier_name. Type the SQL query in the box provided.
SELECT *
FROM suppls
WHERE suppl_name NOT LIKE '%o%';
Four entries will be chosen. These are the results you want to achieve.
| suppl_id | suppl_name | city_id | state_id |
| 100 | Yandex | Moscow | Russian |
| 300 | Oracle | Redwood City | California |
| 400 | Bing | Redmond | Washington |
| 700 | Qwant | Paris | France |
In this example, there are four entries in the suppliers table where suppl_name does not contain liters ‘o’.
Using NOT with BETWEEN condition
The NOT operator can also be combined with the BETWEEN condition to create the NOT BETWEEN condition. Let us consider an example that shows how to use the NOT BETWEEN condition in a query.
In this example, we have a table with the following data:
| custom_id | f_name | l_name | fav_website |
| 4000 | Justin | Bieber | google.com |
| 5000 | Selena | Gomez | bing.com |
| 6000 | Mila | Kunis | yahoo.com |
| 7000 | Tom | Cruise | oracle.com |
| 8000 | Johnny | Depp | NULL |
| 9000 | Russell | Crowe | google.com |
Enter the following SQL statement.
SELECT *
FROM customs
WHERE custom_id NOT BETWEEN 5000 AND 8000;
Two records will be chosen. Here are the results that you should get.
| custom_id | f_name | l_name | fav_website |
| 4000 | Justin | Bieber | google.com |
| 9000 | Russell | Crowe | google.com |
This will return all lines where customer_id is not in the range between 5000 and 8000 inclusive. This would be equivalent to the next SELECT operator.
SELECT *
FROM customs
WHERE custom_id < 5000
OR custom_id > 800;
Using NOT with EXISTS condition
Finally, the NOT condition can be combined with the EXISTS condition to create the NOT EXISTS condition. Let’s look at an example which shows how to use the NOT EXISTS condition in SQL.
In this example we have a table with the following data:
| custom_id | f_name | l_name | fav_website |
| 4000 | Justin | Bieber | google.com |
| 5000 | Selena | Gomez | bing.com |
| 6000 | Mila | Kunis | yahoo.com |
| 7000 | Tom | Cruise | oracle.com |
| 8000 | Johnny | Depp | NULL |
| 9000 | Russell | Crowe | google.com |
also a table with the following information:
| ord_id | custom_id | ord_date |
| 1 | 7000 | 2019/06/18 |
| 2 | 5000 | 2019/06/18 |
| 3 | 8000 | 2019/06/19 |
| 4 | 4000 | 2019/06/20 |
| 5 | NULL | 2019/07/01 |
Enter the following SQL statement.
SELECT *
FROM customs
WHERE DOES NOT EXIST
(SELECT *
FROM ords
WHERE customs.custom_id = ords.custom_id);
Two entries will be chosen. The outcomes you should see are listed below.
| custom_id | f_name | l_name | fav_website |
| 6000 | Mila | Kunis | yahoo.com |
| 9000 | Russell | Crowe | google.com |
Since the order table does not contain any records for this custom_id, all records from the customer’s table are returned in this example.
AND OR and NOT Operators in sql
About Enteros
Enteros offers a patented database performance management SaaS platform. It finds the root causes of complex database scalability and performance problems that affect business across a growing number of cloud, RDBMS, NoSQL, and machine learning database platforms.
The views expressed on this blog are those of the author and do not necessarily reflect the opinions of Enteros Inc. This blog may contain links to the content of third-party sites. By providing such links, Enteros Inc. does not adopt, guarantee, approve, or endorse the information, views, or products available on such sites.
Are you interested in writing for Enteros’ Blog? Please send us a pitch!
RELATED POSTS
Driving Cost-Efficient Innovation: Enteros Performance Management Platform for Accurate Technology Cost Estimation
- 15 December 2025
- Database Performance Management
Introduction The technology sector is at the epicenter of global innovation. From cloud-native applications and SaaS platforms to AI-driven analytics and real-time digital services, modern technology organizations operate in environments defined by speed, scale, and complexity. However, as innovation accelerates, so do operational challenges—particularly around performance management, cloud cost estimation, and financial predictability. Today’s technology … Continue reading “Driving Cost-Efficient Innovation: Enteros Performance Management Platform for Accurate Technology Cost Estimation”
Future-Ready Fashion Tech: How Enteros Combines Database Optimization and Cloud FinOps for Smarter Operations
Introduction The fashion industry has evolved far beyond seasonal collections and brick-and-mortar storefronts. Today’s fashion brands operate as highly digital, data-driven enterprises—powered by eCommerce platforms, global supply chain systems, AI-powered demand forecasting, personalization engines, and SaaS-based retail applications. At the heart of this transformation lies a complex web of databases, cloud resources, and analytics platforms. … Continue reading “Future-Ready Fashion Tech: How Enteros Combines Database Optimization and Cloud FinOps for Smarter Operations”
Precision Banking Operations: How Enteros Uses AIOps to Enhance Performance Management and Cost Estimation
- 14 December 2025
- Database Performance Management
Introduction The banking sector is at the center of a profound digital transformation. Core banking platforms, digital wallets, real-time payments, mobile apps, fraud detection engines, and regulatory reporting systems now operate on always-on, data-intensive infrastructures. As customer expectations for speed, reliability, and personalization rise, banks face unprecedented pressure to ensure flawless system performance, while simultaneously … Continue reading “Precision Banking Operations: How Enteros Uses AIOps to Enhance Performance Management and Cost Estimation”
Driving Retail Profitability: How Enteros Uses Cloud FinOps to Modernize Cost Attribution
Introduction The retail industry is operating in one of the most competitive and digitally demanding environments in history. Omnichannel commerce, dynamic pricing, real-time inventory visibility, personalized customer experiences, and AI-driven demand forecasting have become table stakes. Behind every seamless retail experience lies a complex web of cloud infrastructure, SaaS platforms, databases, and data pipelines. However, … Continue reading “Driving Retail Profitability: How Enteros Uses Cloud FinOps to Modernize Cost Attribution”