← IGCSE Computer Science Paper 2

SQL COUNT function

SQL function that counts records. SELECT COUNT(*) FROM Students; outputs one row with the number of records in the table. It counts rows, whereas SUM adds up values.

Understanding SQL COUNT function in IGCSE Computer Science Paper 2

What it does: COUNT(*) gives the number of records in the table as one row of output. SUM adds the values together, whereas COUNT only counts how many records there are. The clause order must be SELECT, FROM, then WHERE. FROM must come before WHERE. COUNT is a function, so the * must be inside brackets: COUNT(*). The correct statement is SELECT COUNT(*) FROM Students; because FROM names the table.

Common mistakes: The closing bracket is missing from the COUNT function. It should be SELECT COUNT(*). SQL uses a single = to compare values in a WHERE condition, not ==. It should be WHERE Year = 9;.

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 525–538) and word search (Modules 500–538).

Take this worksheet further — free with Cloodit

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

Learning
Duo
Which query tells you how many records are in the Students table?
SELECT COUNT(*) FROM Students;SELECT SUM(*) FROM Students;
Matches
SELECT COUNT(*) Students;
↓
The FROM keyword is missing, so the SQL does not say which table to count the records in.
Applying
Meanings
Term
COUNT(*)
Meaning
SQL function that counts records. SELECT COUNT(*) FROM Students; outputs one row with the number of records in the table. It counts rows, whereas SUM adds up values.
Practice
SELECT COUNT(*) FROM students;
Testing
Gaps
SELECT (*) FROM Students;
Check Answer
Spots
2FROM Students
3SELECT COUNT(*

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

The 'Lion' badge — Inheritance King, 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. Which query tells you how many records are in the Students table?
A. SELECT COUNT(*) FROM Students; ✓
B. SELECT SUM(*) FROM Students;
COUNT(*) counts the records in the table. SUM adds up the values in a numeric field, and it cannot be used with *.
2. How many rows of output does SELECT COUNT(*) FROM Students; produce?
A. One row containing a single number ✓
B. One row for every record in the table
COUNT is an aggregate function. It combines all the records into a single value, so the output is one row.
3. What does COUNT(*) do?
A. Adds up the values in every field
B. Counts the number of records ✓
COUNT(*) counts records (rows). Adding up values is the job of SUM.
4. A table has 25 records. What does SELECT COUNT(*) FROM Students; output?
A. 25 ✓
B. The 25 student names, one per row
The output is just the number of records, which is 25, not the data in the records.
5. Which function would you use to find out HOW MANY students there are in a table?
A. SUM
B. COUNT ✓
COUNT tells you how many records there are. SUM gives the total of the values in a numeric field, such as the total of all the marks.

Match the Pairs

SELECT COUNT(*) FROM Students; → Outputs one row containing the number of records in the Students table.
SELECT COUNT(StudentID) FROM Students WHERE Year = 10; → Counts only the records where Year is 10 and outputs that total.
To find how many records are in a table called Books, use COUNT rather than listing every record. → SELECT COUNT(*) FROM Books;
To add up the values in a numeric Price field instead of counting records, use SUM, not COUNT. → SELECT SUM(Price) FROM Books;
SELECT COUNT(*) Students; → The FROM keyword is missing, so the SQL does not say which table to count the records in.
SELECT SUM(*) FROM Students; → SUM was used to count records. SUM adds up the values of a numeric field and cannot be used with *. COUNT(*) should be used.

Key Term

COUNT(*)
SQL function that counts records. SELECT COUNT(*) FROM Students; outputs one row with the number of records in the table. It counts rows, whereas SUM adds up values.

Fill in the Blanks

1. SELECT COUNT(*) FROM Students;
Hint: Type the SQL function that counts how many records there are.
2. SELECT COUNT(*) FROM Students;
Hint: Type the symbol that means all fields, so every record is counted.
3. SELECT COUNT(*) FROM Students;
Hint: Type the keyword that names the table to count records in.
4. SELECT COUNT(*) FROM Students WHERE Year = 9;
Hint: Type the keyword that picks which records are counted.
5. SELECT SUM(Points) FROM Students;
Hint: Type the function that adds up the values in a field instead of counting records.

Spot the Error

Question 1
A SELECT COUNT(*)
B FROM Students
C SELECT COUNT(*
Line C — The closing bracket is missing from the COUNT function. It should be SELECT COUNT(*).
Question 2
A SELECT COUNT(StudentID)
B FROM Students
C WHERE Year == 9;
Line C — SQL uses a single = to compare values in a WHERE condition, not ==. It should be WHERE Year = 9;
Question 3
A SELECT SUM(*)
B FROM Books
C WHERE Price > 10;
Line A — SUM adds up the values in a numeric field, so it cannot be used with *. To count how many records match, use SELECT COUNT(*).
Question 4
A SELECT COUNT(*)
B FROM Students
C WHERE Year = 10
D AND House = Blue;
Line D — Text values in a WHERE condition must be inside quotes. It should be AND House = 'Blue';
Question 5
A SELECT COUNT(*)
B FORM Students
C WHERE Points >= 100;
Line B — The keyword is misspelt. It should be FROM, which names the table being counted.

Student with a class code? Join your class →