In Oracle the NOT IN operator used to compare a column with one or more than one value.
It is often used in conjunction with the SELECT statement to retrieve data from a table that doesn't match any of the values in a given list.
It always used with where clause.
Here's the basic syntax of the NOT IN operator:
SELECT column1, column2, ...
FROM table_name
WHERE column_name NOT IN (value1, value2, ...);
Suppose we have to fetch all record from the user_table where city name is not equal to Pune, Mumbai.In this case we have to use NOT IN operator.
Sl No | Name | City | Email ID |
---|---|---|---|
1 | Virat | Delhi | virat@gmail.com |
2 | Sachin | Mumbai | sachin@gmail.com |
3 | Dhoni | Ranchi | dhoni@gmail.com |
4 | Raina | Pune | raina@gmail.com |
SELECT * FROM user_table
WHERE City NOT IN ('Pune', 'Mumbai');
Sl No | Name | City | Email ID |
---|---|---|---|
1 | Virat | Delhi | virat@gmail.com |
3 | Dhoni | Ranchi | dhoni@gmail.com |