Skip to content
CodeItRaw
SQL: Select and Filter

Lesson 2/3

WHERE passes the rows through a condition: those that meet it stay, the others go. The condition is asked of each row on its own; think of Python's if, run separately for every row.

SELECT title, price
FROM books
WHERE price < 100
AND (genre = 'poetry' OR genre = 'essay');
Equality is written with a single = (not Python's ==), and texts go in single quotes. AND wants both conditions, OR either. This query brings the poetry and essay books that cost less than 100.

When you compare the same column with several values, IN reads better: genre IN ('poetry', 'essay'). For a range you write BETWEEN 50 AND 100, which includes both ends.

Tasks

Tasks open in order. Solve them all and the next lesson opens.

This lesson's tasks open when the lessons before it are finished. You can read the explanation now.Go to the current lesson

  1. 01

    Filter

    SQL query

  2. 02

    Several conditions

    SQL query

If you would rather not wait for the order, every problem is open without locks: Problem list