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
| Word | What it means | Example |
|---|---|---|
| Query | a question you ask a table of data | |
| Sort | to put records in order | |
| Criterion | a test a record must pass to be shown | age >= 15 |
| Logical operator | AND, OR or NOT, used to join criteria | |
| Wildcard | a 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 questionsYour 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
-- 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 questionsYour answers are marked here and are not kept. A college account keeps every student’s marks.