Lesson 8: Filtering results using the WHERE Clause and the IN operator.

By Alan Hylands — 1 minute read

Tidying up our WHERE clause with IN.

You can see from the previous OR operator example how your WHERE clause could get a little unwieldy after a while when using multiple different conditions.

If we were also specifying date ranges, upper and lower price limits, types of holiday, number of passengers etc. as well it could become VERY untidy to read and maintain.

We can do a little housekeeping to protect against that in our IDE by using brackets and liberal use of tabs. To tidy up the multiple OR conditions themselves we could also use the IN statement.

E.g.

SELECT * 
FROM holidays
WHERE Country IN ('Spain','Portugal','Greece');

Quiz Time.

The Question.

Let's tidy up the query from the last lesson. Use the IN keyword to bring back the same results i.e. everyone who has black OR brown hair.

The Data.

The Editor.


Run SQL


Show Answer

The Answer.

Correct SQL:

                    SELECT * FROM characters WHERE hair IN ('Black','Brown');
                    

Correct Output:

Try the next lesson