Understand and write basic SQL queries using SELECT, WHERE, AND, OR, ORDER BY, COUNT and SUM. Identify a suitable primary key, choose appropriate data types, and recognise why NULL values are not allowed in a primary key when defining a single‑table database.
NULL.StudentID) is acceptable only if it meets the three criteria above.| Data type | Typical use | Exact syllabus syntax | Example value |
|---|---|---|---|
| INTEGER | Whole numbers | INTEGER | 16 |
| REAL | Numbers with decimals | REAL | 92.5 |
| CHAR / STRING | Text (fixed or variable length) | CHAR(n) or STRING | 'Alice' (CHAR(5) or STRING) |
| BOOLEAN | True/False values | BOOLEAN | TRUE |
| DATE / TIME | Calendar dates or times | DATE or TIME | '2025‑12‑30' |
CHAR must specify a length, e.g. CHAR(1) for a single character.STRING has no length limit in the syllabus; teachers may impose a reasonable limit for assessment.NULL in a primary‑key column.
CREATE TABLE Students (
StudentID INTEGER PRIMARY KEY,
Name STRING,
Age INTEGER,
Gender CHAR(1), -- ‘M’ or ‘F’
Grade CHAR(1), -- A, B, C …
Score INTEGER,
BirthDate DATE
);
| StudentID | Name | Age | Gender | Grade | Score | BirthDate |
|---|---|---|---|---|---|---|
| 1 | Alice | 16 | F | A | 92 | 2007‑04‑12 |
| 2 | Bob | 15 | M | B | 85 | 2008‑09‑23 |
| 3 | Charlie | 17 | M | A | 88 | 2006‑02‑05 |
| 4 | Diana | 16 | F | C | 73 | 2007‑11‑30 |
| 5 | Edward | 15 | M | B | 79 | 2008‑07‑14 |
SELECT StatementRetrieves data from a table. Keywords are conventionally written in upper‑case (examiners ignore case, but the style helps readability).
SELECT column1, column2, … FROM table_name;
* to select all columns.WHERESELECT column1, column2 FROM table_name WHERE condition;
=, <>, <, >, <=, >=.AND & ORAND – both conditions must be true.OR – at least one condition must be true.( ) to control evaluation order.SELECT Name, Score FROM Students WHERE Gender = 'F' AND (Grade = 'A' OR Score > 90) ORDER BY Score DESC;
ORDER BYASC).DESC for descending order.SELECT column1, column2 FROM table_name WHERE condition ORDER BY column1 ASC, column2 DESC;
COUNT(column) – number of rows (or non‑NULL values) in the column.SUM(column) – total of all numeric values in the column.AS alias_name) is optional but useful; the alias appears in the answer sheet.-- How many students scored above 80? SELECT COUNT(*) AS NumHighScorers FROM Students WHERE Score > 80; -- Total of all scores (for a later average calculation) SELECT SUM(Score) AS TotalScore FROM Students;
SELECT Name, Score FROM Students WHERE Score > 80;
SELECT * FROM Students WHERE Gender = 'F' AND (Grade = 'A' OR Score > 90);
SELECT Name, Score FROM Students ORDER BY Score DESC, Name ASC;
SELECT StudentID FROM Students WHERE Age <= 15;
SELECT COUNT(*) AS NumAStudents FROM Students WHERE Grade = 'A';
SELECT SUM(Score) AS TotalScore FROM Students;
SELECT Name, BirthDate FROM Students WHERE BirthDate > '2007-01-01';
Name and Grade of all male students.Score between 80 and 90 inclusive.Name, Age and Score of students whose Grade is not ‘C’.Gender is ‘F’ and Age is greater than 15, sorted by Score from highest to lowest.Name?SELECT chooses which columns to display.WHERE limits rows based on one or more conditions.AND and OR combine conditions; parentheses control precedence.ORDER BY sorts the final result set (ASC or DESC).COUNT and SUM are the only aggregation functions required for the IGCSE; use AS to give the result a clear alias.CHAR (e.g., CHAR(1)).StudentID) highlighted.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.