NOT IN operator | SQL Tutorial and Query Example

Text copied!

NOT IN operator


  • NOT IN operator :

    NOT IN operator is used to examine if a specific column doesn't match any of the values you specify in 'NOT IN' operator. It is similar to 'not equals to' ( != ) operator in SQL.

    The syntax of the NOT IN operator generally looks like this :
    Here's an example of how you might use the NOT IN operator :

    Let's suppose we have two tables :

    Case - 1 :

    Let's assume you want to retrieve employee data from [Employees] table where Employee_Id doesn't contain value 1, 4, 5.

    Case - 2 :

    • You can also use 'SELECT' statement in 'NOT IN' operator to retrieve list of values from some other table.

    SELECT column_name(s)
    FROM table_name
    WHERE column NOT IN (value1, value2, value3, value4, ...);
            
    To enhance your understanding of 'SQL operators', be sure to check out our next tutorial.
    NOT IN operator
    SELECT *
    FROM [Employees]
    WHERE Employee_Id NOT IN (1,4,5);
            
    NOT IN operator
    SELECT *
    FROM [Employees]
    WHERE Employee_Id NOT IN ( SELECT Employee_Id FROM [Employees_2] );
            
    NOT IN operator

    Frequently Asked Questions :

    Yes, there is a "NOT IN" operator in SQL.
    "NOT" is indeed an operator in SQL.
    There is no "not between" operator in SQL, but you can achieve similar functionality using other operators like "NOT BETWEEN".
    The "NOT LIKE" operator in SQL is used to negate a pattern match in a WHERE clause.