Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Preview

AC 2.3: Interrogating a table by sorting and filtering

This is the first page of the lesson. Read it and have a go at the activities. The rest is in the full lesson.

60 minutes

Five hundred loans, one question

A school library has a list of 500 book loans. The librarian asks: who has kept a book longest? Which year group borrows most?

Nobody reads 500 rows. You ask the table questions by changing its order and hiding rows.

Key words

WordWhat it means
Interrogateask a table questions by sorting and filtering it
Sortput the rows in order, using one or more fields
Ascendingsmallest or A first
Descendinglargest or Z first
Filtershow only the rows that meet a test and hide the rest
Fieldone column of a table, such as days
Databasean organised store of tables that you can ask questions
SQLthe language used to ask a database for data

The cells students fill in are left blank in this preview.

By the end of this lesson

Note

I can order a table by a field, sort on two fields, and filter on a field, and say when to use each.

Starter

Have a go

Starter

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Your answers are marked here and are not kept. A college account keeps every student’s marks.

A table as it looks in a spreadsheet

RowA pupilB yearC bookD days
1Amy8Maps5
2Bo7Space2
3Cy8Space2
4Di7Maps5
5Eli9Chess9

The cells students fill in are left blank in this preview.

No spreadsheet here

Important

This platform has no spreadsheet program. Here the cells are a table and the formula is shown as text. You do the same job with code. On site you use a real spreadsheet program.

Three ways to interrogate

TechniqueWhat it doesSpreadsheetSQL
Order by a fieldRows in order of one fieldSort A to Z or Z to A`ORDER BY days DESC`
Sort on several fieldsThe second field breaks tiesAdd a second sort level`ORDER BY year, days`
Filter on a fieldShows only rows that pass a testFilter arrows on the header`WHERE year = 7`

The cells students fill in are left blank in this preview.

Try it: the same questions in SQL

Code: sql
-- Who kept a book longest?
SELECT pupil, days FROM loans ORDER BY days DESC;

-- Year first, then days.
SELECT * FROM loans ORDER BY year, days;

-- Only year 7.
SELECT * FROM loans WHERE year = 7;

A filter hides rows and deletes none

A filter only changes what you can see. The hidden rows are still in the file. Clear the filter and they come back.

Sorting does not delete rows either. It changes their order. Both are safe ways to look at data.

The lesson goes on

5 more parts of this lesson are in the full curriculum, with the tasks, the final check and the labs. A college account gives your students all of it.