☰ Year plan · Communication Technology

Forms and queries

Week 13 · Lesson 9 Forms and Queries · 3 lessons
2

Queries: asking the database a question

ICT Prep 1 Term 1, Lesson 9: pp. 87–97
GoalExplain that a query asks a table a question, and read the parts of a query.
New words
query · a question we ask the database, which answers with only the records and fields we wantcriteria · the conditions a record must meet to appear in the answerrun · to tell the database to find the answer to the queryresult · the small table of records that the query gives back
Explanation

A table may hold thousands of records. We seldom need all of them. A query lets us ask the database a question and get back only the records and fields that answer it. A question such as “Which pupils are in class 1A?” becomes a query. A query has a grid with these rows. Field: which field the column is about. Table: which table the field comes from. Show: a tick if we want to see this field in the answer. Criteria: the condition. The steps are: think of the question, fill in the grid, run the query, read the result. The query does not change the data in the table; it only reads it, like looking through a window. Programs differ in how they draw the grid, so we learn the idea on paper.

Worked examples
FieldNameClass
TablePupilsPupils
Showyesno
Criteria1A
Question: “Which pupils are in class 1A?” In the grid, the field Name is shown, and the field Class has the criterion 1A. The result: Mina and Omar. Two records match.
ABCD
1idNameClassEnglish
21Mina1A15
32Salma1B17
43Omar1A12
54Nour1C19
65Youssef1B14
Look at the pupils’ table. Which records have a Class of 1B? Salma (id 2) and Youssef (id 5). The query returns 2 records out of 5, and the table itself is not changed.
A
1Name
2Nour
Write each question as a query in words: “Show the Name of the pupils whose Class is 1C.” The result has one record: Nour.
Class activity

Use the pupils’ table in this lesson. Write three questions of your own on small cards, such as “Which pupils have an English mark of 15 or more?” For each, say which field has the criterion, which fields to show, and the result. Check each other’s answers.

Practice
1
What does a query do?
2
Name the four rows of the query grid.
3
Put in order: run the query, fill in the grid, read the result, think of the question.
4
Does a query change the data in the table?