← VCE Data Analytics U3O1

One-to-many relationships between tables

One record in a primary table matches many records in a related table. The foreign key sits on the many side, e.g. one class has many students, so class details are not repeated.

Understanding One-to-many relationships between tables in VCE Data Analytics U3O1

What it does: Students is the many side, so it holds the ClassID foreign key that references the primary key in Classes. The teacher is stored once in Classes and the JOIN brings it back for each student using the foreign key, so the data is not repeated. One class record matches 24 student records, which is the pattern of a one-to-many relationship. The 1 marks the one side and the crow's foot (<) marks the many side, so this notation shows a one-to-many relationship.

Common mistakes: To see how many students are in each class, count the matching rows on the 'many' side with COUNT(*). SUM(*) is not valid. It should be SELECT ClassID, COUNT(*). ClassID in Student is a foreign key, not a primary key. If it were a primary key, each class could only appear once, so a class could only have one student. It should be ClassID INT, so many students can share a ClassID.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 17–49) and word search (Modules 17–91).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
In a one-to-many relationship, how many records in the related table can match ONE record in the primary table?
Many recordsOnly one record
Matches
Classes table: ClassID (PK), Teacher, Student1, Student2, Student3
↓
Student names are stored as repeating columns in the one side's table. Instead, create a Students table with a ClassID foreign key, with one row per student.
Applying
Meanings
Term
one-to-many relationship
Meaning
One record in a primary table matches many records in a related table. The foreign key sits on the many side, e.g. one class has many students, so class details are not repeated.
Practice
SELECT students.firstName, results.mark
Testing
Gaps
SELECT * FROM WHERE classId = 3;
Check Answer
Spots
1SELECT ClassID, SUM(*)
2FROM Student

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Bear' badge — Forest Guardian, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. In a one-to-many relationship, how many records in the related table can match ONE record in the primary table?
A. Only one record
B. Many records ✓
One record on the 'one' side (e.g. one class) can match many records on the 'many' side (e.g. many students).
2. A school database has a Classes table and a Students table. Which statement describes the relationship?
A. One class has many students ✓
B. One student has many classes in this design
Each class appears once in Classes, while many student records can belong to that same class.
3. Where does the foreign key go in a one-to-many relationship?
A. In the table on the 'many' side ✓
B. In the table on the 'one' side
The foreign key (e.g. ClassID in Students) sits on the many side and points to the primary key on the one side.
4. Which Students table design correctly links each student to one class?
A. Students(StudentID, Name, ClassID) ✓
B. Classes(ClassID, Room, StudentID)
ClassID is the foreign key in Students. Putting StudentID in Classes would force a class to hold only one student, or repeat the class details.
5. Why use a one-to-many relationship instead of typing the class room and teacher into every student row?
A. It makes every record longer
B. It avoids repeating the same data ✓
Class details are stored once in Classes. Students only store the ClassID, so there is less repeated data and fewer update errors.

Match the Pairs

Students.ClassID (FK) → Classes.ClassID (PK) → Each student row stores the ClassID of one class, so many students can point to the same class record.
Classes (1) ───< Students (many) → One class record is linked to many student records, a one-to-many relationship.
The foreign key goes on the 'many' side of the relationship, so each student stores the class they belong to. → CREATE TABLE Students (StudentID INT PRIMARY KEY, ClassID INT, FOREIGN KEY (ClassID) REFERENCES Classes(ClassID));
Storing the class details once in a Classes table avoids repeating them in every student record. → SELECT Students.Name, Classes.Teacher FROM Students JOIN Classes ON Students.ClassID = Classes.ClassID;
Classes table: ClassID (PK), Teacher, Student1, Student2, Student3 → Student names are stored as repeating columns in the one side's table. Instead, create a Students table with a ClassID foreign key, with one row per student.
Classes table: ClassID (PK), StudentID (FK) → The foreign key is on the 'one' side. It should be on the 'many' side, so Students has ClassID (FK) and Classes has no StudentID.

Key Term

one-to-many relationship
One record in a primary table matches many records in a related table. The foreign key sits on the many side, e.g. one class has many students, so class details are not repeated.

Fill in the Blanks

1. SELECT * FROM students WHERE classId = 3;
Hint: Type the name of the 'many' side table that holds the foreign key and lists every student in class 3.
2. FOREIGN KEY (classId) REFERENCES classes(classId)
Hint: Type the name of the 'one' side table that the foreign key points to.
3. SELECT className, firstName FROM classes JOIN students ON classes.classId = students.classId;
Hint: Type the SQL keyword that combines rows from the two related tables.
4. INSERT INTO students (firstName, classId) VALUES ('Ava', 3);
Hint: Type the foreign key column that links the student to a class, so class details are not repeated.
5. CREATE TABLE classes ( classId INT PRIMARY KEY, className VARCHAR(20));
Hint: Type the constraint that makes each class record unique on the 'one' side.

Spot the Error

Question 1
A SELECT ClassID, SUM(*)
B FROM Student
C GROUP BY ClassID;
Line A — To see how many students are in each class, count the matching rows on the 'many' side with COUNT(*). SUM(*) is not valid. It should be SELECT ClassID, COUNT(*).
Question 2
A CREATE TABLE Student (
B StudentID INT PRIMARY KEY,
C ClassID INT PRIMARY KEY,
D FOREIGN KEY (ClassID)
E REFERENCES Class(ClassID)
F );
Line C — ClassID in Student is a foreign key, not a primary key. If it were a primary key, each class could only appear once, so a class could only have one student. It should be ClassID INT, so many students can share a ClassID.
Question 3
A SELECT c.ClassName, s.Name
B FROM Class c JOIN Student s
C ON c.ClassID = s.StudentID;
Line C — The join must match the primary key in Class with the foreign key in Student. s.StudentID is the student's own key, so the match is wrong. It should be ON c.ClassID = s.ClassID.
Question 4
A SELECT Teacher, StudentName
B FROM Class
C WHERE ClassID = 1;
Line A — The query reads from the Class table, but StudentName is stored in the Student table on the 'many' side. Class details such as Teacher and ClassName are stored once in Class. It should be SELECT Teacher, ClassName.
Question 5
A CREATE TABLE Class (
B ClassID INT PRIMARY KEY,
C StudentID INT,
D Teacher VARCHAR(30)
E );
Line C — The Class table is the 'one' side, so it must not hold a StudentID. A single StudentID column would let each class link to only one student and put the foreign key on the wrong side. The foreign key ClassID belongs in Student. Line 3 should store class details, e.g. ClassName VARCHAR(20),.

Student with a class code? Join your class →