PostgreSQL NOT IN Condition
In this section, we are going to understand the working of PostgreSQL NOT IN condition, and example of Not IN condition with Numeric and Character values.
Introduction of PostgreSQL NOT IN condition
PostgreSQL NOT IN Condition Syntax
In PostgreSQL, the NOT IN condition can be used with the SELECT, INSERT, UPDATE and DELETE commands.
Example of PostgreSQL NOT IN Condition: with Numeric values
The PostgreSQL NOT IN Operator is used to fetch those rows whose values do not match the list's values.
For this, we are taking the department table from the Javatpoint database.
The following example displays Not IN Operator's use to identify the department information whose emp_id is neither 1 nor 2:
On executing the above command, we will get the below output displaying those records whose emp_id is neither 1 nor 2.
Similarly, we can also use the AND Operator and NOT EQUAL (<>) Operator instead of NOT IN operator as we can see in the following statement:
On implementing the above statement, we will get a similar output compared to the above query output:
Example of PostgreSQL NOT IN Condition: with Character values
For this, we are taking the employee table as above to get that employee information whose emp_fname does not relate to James, Mia employees.
We are using the NOT IN operator in the WHERE clause as we can see the following command:
On executing the above command, we will get the following result:
In the above example, the PostgreSQL NOT IN condition will return all rows from the employee table where the emp_fname is neither 'James' nor 'Mia'.
In the PostgreSQL NOT IN Condition section, we have learned the following topics: