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

Preview

DA 2.3, 2.11: Logical queries find the right rows

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

50 minutes

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

WordWhat it meansExample
Querya question you ask a database
Conditiona test that each row passes or failsday = 'Fri'
Logical operatora word that joins conditionsAND, OR, NOT
Parametera detail that limits a query, such as a day or a price
Booleana value that is only true or false
Databasean 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 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 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

Code: duckdb
select item, qty
from canteen_sales
where day = 'Fri' and item = 'pizza';

-- Try it: change pizza to wrap.

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

8 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.