Lesson 6: Filtering results using the WHERE Clause and the AND operator.

By Alan Hylands — 1 minute read

Leveling up our WHERE clause with AND.

We can power up our WHERE clause even further by using more than one condition at a time. We can join conditions that BOTH have to be met using the AND operator.

Let's say I’m on a travel comparison website looking for a holiday for my family. I know which country I want to visit and what type of holiday we are looking for. I want to see all results which are BOTH in Spain and are Beach holidays.

Nothing else. No city breaks. No camping trips. Not in Italy, France or Greece.

Just beach holidays in Spain.

So I write a SQL query like this:

SELECT * 
FROM holidays
WHERE Country='Spain' AND HolidayType='Beach'

Quiz Time.

The Question.

Sometimes we want to be very specific in what we return from our data table.

Write a query that only brings back black-haired females from our character table.

The Data.

The Editor.


Run SQL


Show Answer

The Answer.

Correct SQL:

                    SELECT * FROM characters WHERE gender='Female' AND hair='Black'
                    

Correct Output:

Try the next lesson