CHECK (value BETWEEN …)).SELECT, FROM, WHERE, ORDER BY,
GROUP BY, HAVING (only with COUNT or SUM).What you will NOT be examined on (to avoid over‑learning):
JOIN operations.STRING_AGG, window functions, or sub‑queries beyond the simple EXISTS check.| Concept | What you need to know |
|---|---|
| Primary key | A column (or combination) that uniquely identifies each record. Must be NOT NULL and contain unique values. |
| Field (column) types | Typical IGCSE types:INTEGER – whole numbersDECIMAL(p,s) – numbers with fixed decimal placesCHAR(n) – fixed‑length text (e.g. CHAR(2) for a state code)VARCHAR(n) – variable‑length text up to n charactersDATE – calendar datesBOOLEAN – TRUE/FALSE
|
| Simple validation (CHECK) | Ensures data entered meets a rule, e.g. CHECK (Mark BETWEEN 0 AND 100) or CHECK (Year IN (9,10,11,12,13)). |
CREATE TABLE Students (
StudentID INTEGER PRIMARY KEY,
FirstName VARCHAR(20) NOT NULL,
LastName VARCHAR(20) NOT NULL,
Year INTEGER CHECK (Year BETWEEN 9 AND 13)
);
Only the concepts above are required for the exam; you will not be asked to write the full CREATE TABLE statement.
The basic structure (always written in upper‑case in exam answers):
SELECT column1, column2, … FROM table_name WHERE condition -- optional, filters rows before any aggregation GROUP BY column1, column2, … -- optional, needed when using COUNT or SUM HAVING aggregate_condition -- optional, filters groups after aggregation ORDER BY column [ASC|DESC]; -- optional, final sorting
FROM – determine the source table.WHERE – keep only rows that satisfy the condition.GROUP BY – form groups (if an aggregate function is used).HAVING – keep only groups meeting the aggregate condition.SELECT – choose columns or calculate aggregates.ORDER BY – sort the final result set.COUNT(column) – number of non‑NULL values.SUM(column) – total of numeric values.When an aggregate is used, every column in the SELECT list must either be aggregated or appear in the GROUP BY list.
Each script below contains blanks (indicated by _____). Fill them in with the correct clause or expression.
SELECT FirstName, LastName, Year FROM Students WHERE _____ ORDER BY Year ASC;
Complete the WHERE clause to show only Year 10 pupils.
List the full names of all Year 10 students.
SELECT CONCAT(FirstName, ' ', LastName) AS FullName
FROM Students
WHERE _____;
Find the total number of students in each year group.
SELECT Year, COUNT(*) AS NumStudents
FROM Students
GROUP BY _____
ORDER BY Year;
Show the average mark for the Enrollments table (single‑table example).
SELECT AVG(Mark) AS AvgMark
FROM Enrollments
WHERE _____; -- e.g. restrict to a particular course if required
Retrieve the IDs of students who have not yet taken any exam (assume a table Results with StudentID).
SELECT s.StudentID
FROM Students AS s
WHERE NOT EXISTS (
SELECT 1 FROM Results r
WHERE r.StudentID = _____
);
Insert a new course called “Geography” worth 3 credits (only the values are required for the exam).
INSERT INTO Courses (CourseID, CourseName, Credits)
VALUES (_____, 'Geography', _____);
Increase every mark that is below 50 by 5 points.
UPDATE Enrollments
SET Mark = Mark + 5
WHERE _____;
| Students |
|---|
StudentID | FirstName | LastName | Year --------------------------------------- 1 | Alice | Brown | 10 2 | Ben | Carter | 11 3 | Clara | Davis | 10 4 | David | Evans | 12 |
| Enrollments |
|---|
EnrollID | StudentID | Mark ----------------------------- 1 | 1 | 78 2 | 1 | 85 3 | 2 | 62 4 | 3 | 90 5 | 4 | 47 |
GROUP BY without aggregating it. Example: SELECT Year, FirstName FROM Students GROUP BY Year; is illegal.WHERE and HAVING. Use WHERE for row filters; HAVING only when a GROUP BY is present.; at the end of every statement.JOIN is required. All IGCSE questions can be answered with a single table.| Clause | Purpose | Typical syntax |
|---|---|---|
SELECT |
Choose columns or aggregates to display | SELECT FirstName, Year |
FROM |
Identify the source table | FROM Students |
WHERE |
Row‑level filter (pre‑aggregation) | WHERE Year = 10 |
GROUP BY |
Group rows for COUNT or SUM |
GROUP BY Year |
HAVING |
Filter groups after aggregation | HAVING COUNT(*) > 5 |
ORDER BY |
Sort the final result set | ORDER BY Year DESC |
Students table.StudentID, FirstName, Year, Mark.SELECT Year, FirstName FROM Students GROUP BY Year;StudentID in the Students table.StudentID – INTEGER (or INT)FirstName – VARCHAR(20) (or CHAR(20) if fixed length)Year – INTEGER with a CHECK (Year BETWEEN 9 AND 13)Mark – INTEGER with CHECK (Mark BETWEEN 0 AND 100)
SELECT FirstName, LastName, Year
FROM Students
WHERE Year = 12
ORDER BY LastName ASC;
SELECT Year, COUNT(*) AS NumStudents
FROM Students
GROUP BY Year
HAVING COUNT(*) >= 3
ORDER BY Year;
FirstName is neither aggregated nor listed in the GROUP BY. Correct version:
SELECT Year, COUNT(*) AS NumStudents
FROM Students
GROUP BY Year;
(If you need FirstName, you must remove GROUP BY or aggregate it appropriately.)Create an account or Login to take a Quiz
Log in to suggest improvements to this note.
Your generous donation helps us continue providing free Cambridge IGCSE & A-Level resources, past papers, syllabus notes, revision questions, and high-quality online tutoring to students across Kenya.