SQL Oracle Java JSP JDBC PHP MORE

Oracle NOT IN Operator with Example

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, ...);
  • column1, column2, ...: The columns you want to retrieve in the result set.
  • table_name: The name of the table you're querying.
  • column_name: The column you want to compare against the list of values.
  • value1, value2, ...: The list of values to check for in the specified column.
Example

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');

Output

Sl No Name City Email ID
1 Virat Delhi virat@gmail.com
3 Dhoni Ranchi dhoni@gmail.com