S6 Term 2 | ICT: SQL Query Results and Join Row Counts – INNER, LEFT, GROUP BY and Normalisation | Tutor Lesson Plan | 45-minute flow, teaching script, common errors, practice with answers
- 2026-12-05
Tutor lesson plan · S6 Term 2 ICT
SQL questions do not test typing; they test whether you can say how many rows come back. This lesson counts join rows, group output and keys in one pass, so every later query question starts with a row count.
01 Prior knowledge check (first 3 minutes)
If any item below is not secure, fix it before this lesson:
| Skill | Quick check | Pass standard |
|---|---|---|
| Skill: primary key | Which column identifies a row in Student | SID; answering SName mixes a descriptor with a key |
| Skill: matching sets | A has 10 and B has 9: which column decides the pairs | The shared SID, not the row number |
| Skill: percentages | What percentage of 9 is 4 | 4 over 9 times 100, which is 44.4 |
02 Lesson flow (45 minutes)
| Time | Stage | Tutor does | Student does |
|---|---|---|---|
| 0-5 min | Diagnose | Ask how many rows each table holds and how many survive the match | Estimates, then checks |
| 5-14 min | INNER and LEFT | Match row by row on SID; S06 has no enrolment, so INNER drops it and LEFT keeps it with NULL | Counts 9 and 10 |
| 14-23 min | GROUP BY | Group the 9 rows by Class for 4, 3 and 2; the largest is 4 over 9, or 44.4 per cent | Fills the group table and the percentage |
| 23-32 min | Keys and normalisation | Each table has a key; Enrol uses (SID, CID); SName depends on SID alone | Names the partial dependency |
| 32-40 min | Query cost | A nested loop compares 10 times 9 for 90; with an index it is 10 plus 9 for 19, saving 71 | Works out 90 and 19 |
| 40-45 min | Exit check | Collect three items and note the failure type | Answers without notes |
03 Teaching script (read it aloud)
Act 1: count rows before writing SQL
Ask the student to repeat: “Student 10, Enrol 9, S06 has none, so INNER gives 9 and LEFT gives 10.”
Act 2: work out the GROUP BY output yourself
Ask the student to repeat: “C1 4, C2 3, C3 2, which makes 9; the largest is 44.4 per cent, and grouping allows only group columns and aggregates.”
Act 3: keys, partial dependency and query cost
Ask the student to repeat: “Composite key (SID, CID); SName alone on SID is a partial dependency; 90 against 19.”
04 Question types and steps
| Type | Example | Steps | Answer |
|---|---|---|---|
| Join row counts | Student 10 rows, Enrol 9, S06 has none | Match by SID; LEFT pads NULL | INNER 9, LEFT 10 |
| GROUP BY | The 9 matched rows by Class | Count each group; the total must be 9 | C1 4, C2 3, C3 2; largest 44.4 per cent |
| Keys | Student, Course, Enrol | A composite key uses two columns; foreign keys point to other keys | (SID, CID); SID and CID are foreign keys |
| Query cost | 10 students over 9 enrolments | No index multiplies, an index adds | 90 against 19, saving 71 |
Left: Student holds 10 rows, Enrol 9, and S06 never enrols (orange). Middle: INNER JOIN keeps the 9 matched rows while LEFT JOIN also keeps S06 for 10. Right: grouping the 9 matched rows by class gives C1 4, C2 3 and C3 2, the largest share being 44.4 per cent.
05 Three independent practice questions
| Question | Answer | What to observe |
|---|---|---|
| Student has 12 rows and Enrol 15, with 3 students holding no enrolment: how many rows for INNER and LEFT? | INNER keeps the 15 matched enrolment rows; LEFT returns 15 plus 3, or 18, with NULL classes for the three students who never enrolled. | Whether three students were confused with three rows |
| By the same data, must the class groups add to 15 or to 18, and why? | They add to 15, because GROUP BY works on the 15 matched rows; the three NULL classes form their own group, which is excluded when the question asks only for real classes. | Whether the NULL group was added in |
| A 500-row table is joined to a 400-row table: how many comparisons without an index, and with one? | Without an index 500 times 400 is 200,000; with an index 500 plus 400 is 900, a saving of 199,100. | Whether the indexed case was multiplied |
06 Common errors and correction lines
| Error | Student usually writes | Tutor says |
|---|---|---|
| LEFT always more rows | “LEFT JOIN always returns more than INNER” | “When every right key matches, they return the same; extra rows are unmatched left rows.” |
| Name outside GROUP BY | “SELECT SName, Class, COUNT(*) … GROUP BY Class” | “SName is neither grouped nor aggregated, so its value is undetermined.” |
| Wrong primary key | “Enrol can use SID as its key” | “A student takes several courses, so the key is (SID, CID).” |
| Cost formulas mixed | “An index still multiplies” | “With an index it is left plus right, so 10 plus 9 gives 19.” |
07 Homework (paper and question numbers)
- S6 ICT paper (set 2), question 9: the keys of three tables and the foreign key in Enrol Student uses SID, Course uses CID and Enrol uses (SID, CID), matching act three
- Question 10: list class sizes with GROUP BY and sort them SELECT Class, COUNT(*) with GROUP BY Class; the row count equals the number of classes
- Question 11: merge three tables and name the partial dependencies SName depends on SID alone and CTitle on CID alone
- Question 12: how many rows INNER and LEFT JOIN return INNER 9 and LEFT 10, the extra row being the student with no enrolment
08 Exit check (last 3 minutes)
| Question | Answer | Verdict |
|---|---|---|
| Student 10 rows, Enrol 9, one student without a class: INNER and LEFT rows? | INNER 9, LEFT 10 | Answering the same for both means the match is unclear: reteach act one |
| The 9 joined rows split by class: what do the three groups add to? | 4 plus 3 plus 2, which is 9 | Answering 8 or 10 means a lost or repeated row: reteach act two |
| What is the primary key of Enrol? | The composite key (SID, CID) | Answering SID or CID alone misses the many-to-many link: reteach act three |
09 Tutor FAQ
Which year is this for?
S6 Term 2 ICT, in the databases and SQL unit. S4 covered relations and normalisation; this lesson fixes query row counts and cost with one method.
Does 45 minutes cover it?
It covers join rows, group output, keys and one cost comparison. Subqueries and views need a separate lesson.
Is there a paper to go with it?
Yes. Homework links to questions 9 to 12 of the S6 ICT paper (set 2), covering keys, GROUP BY, partial dependency and join row counts.
Find a tutor freeTutor sign-up →
©2026 TutorZone · www.tutorzone.com.hk · Terms of use · All rights reserved. Original TutorZone material for personal study and teaching only; not for resale or republication.



