The NOT IN operator is used in WHERE condition with SELECT, UPDATE, and DELETE statement.
The NOT IN operator returns values that do not matches values in a list or subquery.
Syntax
SELECT column_name
FROM table_name
WHERE column_name NOT IN (value1, value2, value3);
Example
SELECT *
FROM Students
WHERE Course NOT IN ('BCA', 'MCA');
This returns students whose course is not BCA and not MCA.
Suppose we have a Students table:
| RollNo | Name | Course |
|---|---|---|
| 101 | Aarav | BCA |
| 102 | Meera | BBA |
| 103 | Kabir | BTech |
| 104 | Riya | MCA |
| 105 | Arjun | BBA |
Query
SELECT *
FROM Students
WHERE Course NOT IN ('BCA', 'MCA');
Result
| RollNo | Name | Course |
|---|---|---|
| 102 | Meera | BBA |
| 103 | Kabir | BTech |
| 105 | Arjun | BBA |
Here, SQL excludes students whose course is BCA or MCA.