IN and NOT IN

Beginner

We can apply slightly more complex filters using the IN and NOT IN clauses, which are especially useful when you want to filter using a list of values.

For example, if we wanted to find all the students in classes 7A, 7B and 8A, we could write the following:

SELECT *
FROM students
WHERE class IN ('7A', '7B', '8A')

Or, if we wanted to find all the students who are not in class 7A or 7B, we could write:

SELECT *
FROM students
WHERE class NOT IN ('7A', '7B')

The NOT IN clause is the negation of the IN clause. It retrieves rows where the specified column's value does not match any value in the list.

Practice

Now it's your turn! Open the following questions in a new tab to try out the IN and NOT IN operators: