Grade 10 Computer Science — Asking a database a question
Read a query as three separate decisions — which fields, which records, in what order — and work out how much comes back.
Name: ________________________
1.A table of pupils has six fields. How many columns does the answer to this query have?
SELECT name, marks FROM pupils WHERE marks > 60
2.A query orders its answer by mark, largest first, and where two records hold the same mark, by roll number, smallest first. Three records come back: roll 7 with mark 91, roll 3 with mark 91, and roll 9 with mark 60. Which roll number is in the top row?
3.A query says SELECT * rather than naming any fields. What comes back?
- a) Nothing, until the fields wanted are named
- b) Every field, for every record that passed the condition
- c) Every record, but only the first field of each
- d) Every field, but only for the first record
4.The answer to a query comes back as twelve rows of four columns. How many single values are in that answer?
5.A query gives back six records and orders them by mark, largest first. The six marks are 44, 91, 67, 91, 30 and 55. What is the mark in the third row of the answer?
6.A table holds five records whose marks are 40, 75, 62, 88 and 51. Match each condition to how many rows a query using it gives back.
- WHERE marks > 60
- WHERE marks > 80
- WHERE marks < 55
- WHERE marks > 30
- WHERE marks >= 51
- 1
- 5
- 4
- 2
- 3
7.Sort each piece of a query by what it decides about the answer.
Groups: Decides which records come back · Decides which fields come back
- WHERE marks > 60
- WHERE house = 'red'
- SELECT name, house, marks
- WHERE marks < 40
- SELECT name, marks
- SELECT roll
8.A table holds forty records. Twenty-five have a mark over 60, thirty are in the swimming team, and twenty are both. How many records satisfy "mark over 60 OR in the swimming team"?
Answer key — Grade 10 Computer Science — Asking a database a question
- 1. 2
- 2. 3
- 3. b) Every field, for every record that passed the condition
- 4. 48
- 5. 67
- 6. WHERE marks > 60 → 3; WHERE marks > 80 → 1; WHERE marks < 55 → 2; WHERE marks > 30 → 5; WHERE marks >= 51 → 4
- 7. WHERE marks > 60 → Decides which records come back; SELECT name, marks → Decides which fields come back; WHERE house = 'red' → Decides which records come back; SELECT roll → Decides which fields come back; WHERE marks < 40 → Decides which records come back; SELECT name, house, marks → Decides which fields come back
- 8. 35