Choosing Rows

WHERE keeps rows where the condition is true. There is no loop: the condition applies to every row at once, which is the mental shift from programming.

Strings use single quotes. Double quotes mean an identifier in standard SQL, so WHERE name = "Butler" may look for a column called Butler rather than the text.

Try it

Combine two conditions with AND. Then try OR. Then mix them without brackets and notice the result is probably not what you meant.

loading editor…
real SQLite, in your browser

Try each of these in turn: BETWEEN 1970 AND 1989, IN (1979, 1987), LIKE 'The %', and title LIKE '%Sower%'.

✦ AND binds tighter than OR

WHERE a = 1 OR a = 2 AND b = 3 means WHERE a = 1 OR (a = 2 AND b = 3), which is rarely what someone intended. Use brackets whenever you mix them. This is not a stylistic preference; it changes the answer.

◈ Graded Query

Return the title and year of every book published before 1980, oldest first. Two columns, in that order.

Checked against the rows your query returns. 1 visible and 2 hidden checks, some against data you cannot see.

loading editor…

Mark this lesson complete

Signed in, your progress follows you to every device.

Next: Practice Test →
← Back