Computer Science · A3.3 Database Programming

A3.3.2 — Constructing Two-Table Queries in SQL

Preview

IB DP Computer Science — A3 Databases — Database programming | SL | A3.3.2

📋 What You Will Learn

  • Construct a JOIN between two tables using their primary-key/foreign-key link
  • Filter rows with WHERE using relational operators, AND, OR, NOT and BETWEEN
  • Match text patterns with LIKE and the % wildcard
  • Order results with ORDER BY … ASC/DESC and remove duplicates with DISTINCT
  • State what GROUP BY and HAVING do to grouped rows
  • Deduce the exact result table a given query produces

🧩 Why This Matters A well-designed database splits data across tables to avoid duplication — but real questions ("which Year 12 students got at least a 5 in Computer Science?") need columns from both tables at once. JOIN is the zip that stitches related rows back together, using the key link the design put there for exactly this purpose.

The Working Schema

Every query in this note runs against these two tables, linked one-to-many: one student has many enrolments. Student.studentID is the primary key;

Continue reading the full note