TopicsCheat sheetLessons
Lurndo › Topics › WHERE

Learn SQL: WHERE

Filtering rows with WHERE

Vic drops a stack of tapes on the counter. "A customer is asking for horror films. Do I really have to go through all 25 titles?" Not while you're here.

WHERE keeps only what's true

With WHERE you put a condition on the rows. The database tests that condition for every row and keeps only the rows for which it is true.

Text goes between single quotes: 'horror'. Without quotes, SQL thinks you mean a column.

SELECT title, genre, year FROM films WHERE genre = 'horror'
Result
titlegenreyear
Alienhorror1979
The Shininghorror1980

Numbers without quotes

Numbers you just write as they are, without quotes. WHERE always comes after FROM: first you say which table, then which rows.

This query finds every film from 2023.

SELECT title, year, price_per_day FROM films WHERE year = 2023
Result
titleyearprice_per_day
Barbie20233.5
Oppenheimer20233.5
Het smelt20233

Try it yourself

Which members live in Mechelen? Show their name and plan.

Ready for more?

The full lesson has 6 exercises, from easy to challenging, with hints, points and a streak you can build.

Start the lesson
← PreviousArithmetic in SELECTNext →Greater, smaller, not equal
SQL topicsCheat sheetExcelLeaderboardAccountPrivacyNederlands