By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
Study Guide: SQL Queries (SELECT, WHERE, JOIN) – Grade 8 Computer Science/ICT
"If a school’s database has thousands of student records, club sign-ups, and attendance logs, how do you pull out just the info you need—like ‘Which 8th graders are in Robotics Club and have perfect attendance?’—without scrolling through every single file? And how does the computer ‘know’ which pieces of data belong together?"
Imagine your school’s database is like a giant Lego city where every brick is a piece of data. The students table is one Lego set (with bricks labeled student_id, name, grade), the clubs table is another (with club_id, club_name, meeting_day), and the attendance table is a third (student_id, date, status). You don’t need to rebuild the whole city to answer a question—you just need to snap the right bricks together using SQL.
student_id
name
grade
club_id
club_name
meeting_day
date
status
SELECT
WHERE
grade = 8
JOIN
Key Vocabulary:- Query: A question you ask the database (e.g., "Show me all 8th graders in Robotics Club"). - Example: Instead of asking your teacher for a list of everyone in the school play, you’d write a query to pull just the cast members from the drama club table.- Table: A structured set of data (like a spreadsheet with rows and columns). - Example: Your school’s lunch menu table has columns for date, main_dish, and allergens. - Grade 9–12 note: In college, tables can have complex relationships (e.g., "many-to-many" between students and clubs), and SQL joins become more nuanced (e.g., LEFT JOIN vs. INNER JOIN).- Primary Key: A unique identifier for each row in a table (like a student ID number). - Example: In a library books table, the ISBN is the primary key—no two books share the same one.- Foreign Key: A column in one table that links to the primary key of another table. - Example: The student_id in the attendance table is a foreign key that points to the student_id in the students table.
main_dish
allergens
LEFT JOIN
INNER JOIN
ISBN
How This Appears on State/ICT Assessments (Grade 8):- Multiple Choice: Questions test syntax (e.g., "Which query returns all students in grade 8?") with distractors like: - Missing WHERE clause (returns all students). - Wrong column name (e.g., SELECT grade instead of SELECT name). - Incorrect join logic (e.g., joining student_id to club_id).- Short Answer: "Write a query to list the names of students in the Chess Club who have missed fewer than 3 days of school." - Proficient response: sql SELECT s.name FROM students s JOIN clubs c ON s.student_id = c.student_id JOIN attendance a ON s.student_id = a.student_id WHERE c.club_name = 'Chess Club' GROUP BY s.name HAVING COUNT(CASE WHEN a.status = 'Absent' THEN 1 END) < 3; - Developing response: Omits the JOIN or miscounts absences (e.g., WHERE a.status = 'Absent' without grouping).- Performance Task: Given a database schema (e.g., pets, owners, vet_visits), write queries to answer questions like "Which owners have cats that visited the vet in 2023?"
SELECT grade
SELECT name
sql SELECT s.name FROM students s JOIN clubs c ON s.student_id = c.student_id JOIN attendance a ON s.student_id = a.student_id WHERE c.club_name = 'Chess Club' GROUP BY s.name HAVING COUNT(CASE WHEN a.status = 'Absent' THEN 1 END) < 3;
WHERE a.status = 'Absent'
Model Proficient Response (Short Answer):Prompt: "Write a query to find all 7th graders who are in the Science Olympiad club."
SELECT s.name FROM students s JOIN clubs c ON s.student_id = c.student_id WHERE s.grade = 7 AND c.club_name = 'Science Olympiad';
Why it’s proficient: - Correctly uses JOIN to link tables.- Filters with WHERE for both grade and club.- Returns only the name column (not all data).
Mistake 1: Forgetting the JOIN Condition- Prompt: "List all students and their club names." - Common Wrong Response: sql SELECT s.name, c.club_name FROM students s, clubs c; - Why It Loses Credit: This creates a Cartesian product (every student paired with every club), not a meaningful connection. The query runs but returns nonsense (e.g., "Ava" paired with "Robotics" and "Chess").- Correct Approach: sql SELECT s.name, c.club_name FROM students s JOIN clubs c ON s.student_id = c.student_id; Key: Always specify how tables relate (ON s.student_id = c.student_id).
sql SELECT s.name, c.club_name FROM students s, clubs c;
sql SELECT s.name, c.club_name FROM students s JOIN clubs c ON s.student_id = c.student_id;
ON s.student_id = c.student_id
Mistake 2: Misusing WHERE for Aggregations- Prompt: "Find students who have missed more than 2 days." - Common Wrong Response: sql SELECT s.name FROM students s JOIN attendance a ON s.student_id = a.student_id WHERE a.status = 'Absent' > 2; - Why It Loses Credit: WHERE filters rows before grouping, so this checks if a single absence record is "greater than 2" (which makes no sense). It doesn’t count absences.- Correct Approach: sql SELECT s.name FROM students s JOIN attendance a ON s.student_id = a.student_id WHERE a.status = 'Absent' GROUP BY s.name HAVING COUNT(a.status) > 2; Key: Use HAVING for conditions after grouping.
sql SELECT s.name FROM students s JOIN attendance a ON s.student_id = a.student_id WHERE a.status = 'Absent' > 2;
sql SELECT s.name FROM students s JOIN attendance a ON s.student_id = a.student_id WHERE a.status = 'Absent' GROUP BY s.name HAVING COUNT(a.status) > 2;
HAVING
Mistake 3: Joining on the Wrong Columns- Prompt: "List all students and their homeroom teachers." - Common Wrong Response: sql SELECT s.name, t.teacher_name FROM students s JOIN teachers t ON s.grade = t.grade; - Why It Loses Credit: This joins students and teachers by grade, which pairs all 8th graders with all 8th-grade teachers (e.g., "Ava" with "Mr. Smith" and "Ms. Lee"). It should join on homeroom_id or similar.- Correct Approach: sql SELECT s.name, t.teacher_name FROM students s JOIN teachers t ON s.homeroom_id = t.homeroom_id; Key: Join on the specific column that links the tables (e.g., homeroom_id, not grade).
sql SELECT s.name, t.teacher_name FROM students s JOIN teachers t ON s.grade = t.grade;
homeroom_id
sql SELECT s.name, t.teacher_name FROM students s JOIN teachers t ON s.homeroom_id = t.homeroom_id;
GROUP BY
SELECT club_name, AVG(grade) FROM students GROUP BY club_name
"If you run SELECT * FROM students JOIN clubs ON students.student_id = clubs.student_id, but some students aren’t in any clubs, their names disappear from the results. Why? And how would you modify the query to show all students, even those without clubs?"
SELECT * FROM students JOIN clubs ON students.student_id = clubs.student_id
Pointer Toward the Answer: This happens because JOIN (or INNER JOIN) only returns rows where there’s a match in both tables. To include students without clubs, you’d use a LEFT JOIN:
SELECT s.name, c.club_name FROM students s LEFT JOIN clubs c ON s.student_id = c.student_id;
Now, students without clubs appear with NULL for club_name. This is a key difference between INNER JOIN and LEFT JOIN—one is exclusive, the other inclusive. (Bonus: What would RIGHT JOIN do here?)
NULL
RIGHT JOIN
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.