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

Preview

Unit 6 C1: Sorting and searching with queries

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

55 minutes

Find the right members fast

Oakfield Youth Club is made up. It has 200 members. The manager asks three things in one morning.

Who is the youngest member? Which members are 15 or older and live in Oakfield? Who has a first name that starts with S? A query (a question you ask a table of data) answers each one in a second.

By the end of this lesson

Note

I can sort records and write a query with several criteria across linked tables.

Key words

WordWhat it meansExample
Querya question you ask a table of data
Sortto put records in order
Criteriona test a record must pass to be shownage >= 15
Logical operatorAND, OR or NOT, used to join criteria
Wildcarda symbol that stands for any letters

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

Starter: what you already know

Have a go

Starter: what you already know

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.

Sorting puts records in order

To sort is to put records in order. Sort on one field, such as age. Sort on two fields to settle ties: last name first, then first name.

In SQL (a language for working with tables), ORDER BY sorts. It goes from smallest to largest unless you add DESC, which means the other way.

Try it: put members in order

Code: sql
-- Sort on one field: the youngest members first.
SELECT first_name, last_name, age FROM members ORDER BY age;

-- Sort on two fields: last name, then first name for ties.
SELECT first_name, last_name FROM members ORDER BY last_name, first_name;

-- Add DESC after age in the first query to put the oldest first.

Check

Have a go

Check

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.

The lesson goes on

10 more parts of this lesson are in the full lesson, which colleges teach from the Library. A college account gives your students all of it.