← Teacher guide

Keep only the rows you want

Students filter rows with WHERE, using text in quotes and numbers with > and <.

SQL and databases · Ask a table · about 25 minutes · Open the student lesson

Classroom resources

Open these in Waypoints Prepare with one click. To share a file another way, copy its address and paste it into Load URL, or download the file and import it. In Prepare, the worksheet's Teacher edition shows the answers; the student copy hides them.

Students will be able to

Timing

Predict and Run 8 min · Investigate 8 min · Modify and Make 9 min

Running the lesson

  1. Predict: the error option catches students who think pop must be a column.
  2. Run: change the genre and run again, then ask what happens with a genre that does not exist (no rows, no error).
  3. Investigate: the quotes question is the main idea. Ask what SQL does with a word that has no quotes.

In class

On the slides at these points. Students can do the whole lesson on their own; these are for the room. In the deck, the Run, Modify and Make slides have the live playground in them (the tutorial link is the backup), and the notes above are in each slide's speaker notes.

The hard part (on purpose)

Quotes. Ask: is this word a column or a value? Columns have no quotes; text values do.

When students get stuck

What you will seeA question to askThe fix
no such column: popIs pop a column, or a value in a column?Put single quotes round the text value.
No rows come back.How is the genre spelled in the table?Match the spelling in the data. Text must match letter for letter.

Answers to the checks

  1. Predict: Four of the 15 songs are pop. What will this show?
    4 rows. WHERE tests every row and keeps only those where the test is true.
  2. Count the long songs: Run the query. How many songs are longer than 250 seconds?
    4
  3. Quotes: Why does WHERE genre = pop (no quotes) give an error?
    pop looks like a column name
    Without quotes, pop looks like a column name, and there is no such column. Quotes make a value of text. Without them SQL thinks pop is the name of a column.
  4. Write the test: Which query finds songs released after 2021?
    SELECT title FROM songs WHERE year > 2021;
    A test has a column, a comparison and a value: year > 2021.

Solutions

One possible solution for each task. Other correct programs are fine.

Modify

SELECT title
FROM songs
WHERE artist = 'Kito';

Make

SELECT title, plays
FROM songs
WHERE plays > 5000;

Stretch and support

Stretch: Combine two tests (next lesson uses AND) or try year >= 2022.

Support: Give the WHERE line with the value missing.

Exit ticket

What does WHERE do, and why is 'pop' in quotes?

It keeps only the rows where the test is true. Quotes show that pop is a value, not a column.

What each step is for

Where it leads

Next lesson: put the rows in order and show only the top few.