NOT IN Operator with SELECT Statement
We can also use the NOT IN operator with a subquery of the WHERE Clause, We can return a list of records from the main query that are not present in the subquery of WHERE clause.
Query
SELECT * from Emp Where EMP_id NOT IN (SELECT Emp-Id from Account_details );
The above Query will return a list of records from the Emp table that are present in the the Account_details table.
SQL NOT IN Operator
In SQL Server, the NOT IN operator replaces a set of arguments with the <> or != operator that is combined with the AND operator. This operator can be used to make code more readable and easier to understand for SQL statements like SELECT, UPDATE, and DELETE. In most cases, it won’t affect performance.
Syntax:
SELECT column_name(s)
FROM table_name
WHERE column_name NOT IN (list_of_values);
Let’s create a database to understand NOT IN Operator in SQL.