Introduction
SQL is a versatile and powerful tool that can perform various complex operations on data. One such operator, often used but not always completely understood, is the NOT IN operator.

In this article, we'll break down how it works and provide you with real-world examples to enhance your understanding.
What is the SQL 'NOT IN' Operator?
The SQL 'NOT IN' operator is used to exclude certain values in a WHERE clause. It can be seen as the opposite of the IN operator, as it selects rows where a certain column's value does not exist in a set of given values.
The basic syntax for the 'NOT IN' operator is:
SELECT column1, column2,...
FROM table_name
WHERE column_name NOT IN (value1, value2,...);
Usage of the 'NOT IN' Operator
Let's consider a simple example where we have a table named 'Orders'. Here is a snapshot of the 'Orders' table:
OrderID Product Quantity
1 Apple 30
2 Banana 20
3 Orange 10
4 Mango 40

Now, let's say we want to find all the orders that are not for 'Apple' or 'Banana'. We can use the NOT IN operator to achieve this:
SELECT *
FROM Orders
WHERE Product NOT IN ('Apple', 'Banana');
The result would be:
OrderID Product Quantity
3 Orange 10
4 Mango 40

Considerations When Using 'NOT IN'
When using the NOT IN operator with subqueries, be cautious about NULL values. If any value in the subquery result is NULL, the NOT IN operator will return an empty set, regardless of other matches.To avoid this, you can explicitly exclude NULLs from your subquery or use the NOT EXISTS operator, which handles NULL values more predictably.