Only the Friday pizza
The canteen manager asks one question: "How many pizzas did we sell on Friday?"
Nobody wants every row of the week. A logical search picks out exactly the rows that answer the question.
Key words
| Word | What it means | Example |
|---|---|---|
| Query | a question you ask a database | |
| Condition | a test that each row passes or fails | day = 'Fri' |
| Logical operator | a word that joins conditions | AND, OR, NOT |
| Parameter | a detail that limits a query, such as a day or a price | |
| Boolean | a value that is only true or false | |
| Database | an organised store of data that you can search |
The cells students fill in are left blank in this preview.
By the end of this lesson
Note
I can write a condition with AND, OR and NOT to find the rows I need.
Starter
Have a go
Starter
3 questionsYour answers are marked here and are not kept. A college account keeps every student’s marks.
A logical query searches accurately
The purpose of a query is to search for the data you need, and no more. It tests each row against a condition.
A condition gives a Boolean answer: true or false. Only rows where it is true come back.
Try it: one condition
select item, qty
from canteen_sales
where day = 'Fri' and item = 'pizza';
-- Try it: change pizza to wrap.
Check
Have a go
Check
3 questionsYour answers are marked here and are not kept. A college account keeps every student’s marks.