How is SQL used to define a database and to query and update the data it holds?
Structured Query Language - data definition (CREATE TABLE) and data manipulation (SELECT with WHERE, ORDER BY, joins and aggregate functions, plus INSERT, UPDATE and DELETE).
A CCEA A-Level Software Systems Development answer on Structured Query Language: defining tables with CREATE TABLE, and querying and updating data with SELECT, WHERE, ORDER BY, joins, aggregate functions, INSERT, UPDATE and DELETE.
Reviewed by: AI editorial process; not yet individually human-reviewed
Have a quick question? Jump to the Q&A page
Jump to a section
What this dot point is asking
CCEA expects you to read and write Structured Query Language (SQL): the data definition statement CREATE TABLE (with keys), and the data manipulation statements SELECT (with WHERE, ORDER BY, joins and aggregate functions) plus INSERT, UPDATE and DELETE. Writing a SELECT with conditions and sorting, a query with a join, and an aggregate with GROUP BY are high-mark questions, so the syntax must be accurate.
The answer
Defining a database (data definition)
CREATE TABLE Student (
studentID INTEGER PRIMARY KEY,
surname VARCHAR(30),
yearGroup INTEGER,
mark INTEGER
);
CREATE TABLE names the table and lists each field with its data type, marking the primary key (a foreign key would be declared with REFERENCES to the related table).
Querying data with SELECT
SELECT surname, mark
FROM Student
WHERE yearGroup = 13 AND mark >= 60
ORDER BY mark DESC;
Joins, aggregates, and changing data
A join combines rows from related tables on a matching column, usually a foreign key to a primary key, so a query can return data spread across tables:
SELECT Order.orderID, Customer.name
FROM Order
INNER JOIN Customer ON Order.customerID = Customer.customerID;
Aggregate functions summarise many rows into one value: COUNT, SUM, AVG, MAX, MIN, often with GROUP BY to summarise per group:
SELECT yearGroup, AVG(mark) AS averageMark
FROM Student
GROUP BY yearGroup;
The DML statements that change data:
INSERT INTO Student (studentID, surname, yearGroup, mark)
VALUES (101, 'Murphy', 13, 72);
UPDATE Student SET mark = 75 WHERE studentID = 101;
DELETE FROM Student WHERE studentID = 101;
Worked example: building up a query with an aggregate
Examples in context
Example 1. A shop's sales report. Management want total sales per product. A query joins OrderLine to Product, groups by product name, and uses SUM(quantity * price) with ORDER BY to rank products by revenue. One SQL statement turns thousands of rows across two tables into a tidy ranked summary, which is why aggregates and joins are core skills.
Example 2. Maintaining the data. When a customer changes address, a single UPDATE Customer SET address = '...' WHERE customerID = 42; corrects it once, and referential integrity keeps their orders linked. A mistaken row is removed with a carefully targeted DELETE using a WHERE clause; omitting the WHERE would delete every row, a classic and serious error.
Try this
Q1. Write SQL to list all fields of every Product whose price is below 10. [2 marks]
- Cue.
SELECT * FROM Product WHERE price < 10;
Q2. State the difference between the WHERE and HAVING clauses. [2 marks]
- Cue.
WHEREfilters individual rows before grouping;HAVINGfilters the groups after aGROUP BYand can use aggregate functions.
Q3. Name three SQL aggregate functions. [3 marks]
- Cue. Any three of
COUNT,SUM,AVG,MAX,MIN.
Exam-style practice questions
Practice questions written in the style of CCEA exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.
CCEA 20196 marksA Student table has fields studentID, surname, yearGroup and mark. Write SQL to list the surname and mark of every Year 13 student whose mark is at least 60, sorted by mark in descending order.Show worked answer →
A SELECT query chooses columns with SELECT, the table with FROM, the rows with WHERE, and the order with ORDER BY.
SELECT surname, mark
FROM Student
WHERE yearGroup = 13 AND mark >= 60
ORDER BY mark DESC;
SELECT names the two columns to display, FROM names the table, WHERE filters to Year 13 students with a mark of 60 or more (both conditions joined with AND), and ORDER BY mark DESC sorts the results from highest mark to lowest. A text value such as a surname would be quoted, but yearGroup and mark are numeric here.
Markers reward SELECT of the correct two fields, FROM the correct table, a WHERE clause with both conditions combined by AND, and ORDER BY mark in descending order (DESC).
CCEA 20216 marksExplain the purpose of a SQL join, and write a query that uses a join to list each order's orderID together with the name of the customer who placed it, given an Order table (orderID, customerID) and a Customer table (customerID, name).Show worked answer →
A join combines rows from two (or more) tables based on a related column, usually matching a foreign key in one table to the primary key in the other. It lets a query return data that is spread across related tables as if it were one table, which is the whole point of splitting data relationally.
SELECT Order.orderID, Customer.name
FROM Order
INNER JOIN Customer ON Order.customerID = Customer.customerID;
The INNER JOIN matches each order to the customer whose customerID equals the order's customerID, so the result pairs every orderID with the correct customer name. Qualifying the column names with the table name (Order.orderID) avoids ambiguity where both tables share a column name.
Markers reward explaining a join as combining related tables on a matching column (foreign key to primary key), and a correct query that joins Order and Customer on customerID and selects the orderID and the customer name.
Related dot points
- Relational database concepts - tables, records and fields, primary and foreign keys, relationships, referential integrity, and the advantages over flat files.
A CCEA A-Level Software Systems Development answer on relational database concepts: tables, records and fields, primary and foreign keys, relationships, referential integrity, and the advantages of a relational database over flat files.
- Entity relationship modelling (entities, attributes, relationships and cardinality) and normalisation to first, second and third normal form.
A CCEA A-Level Software Systems Development answer on entity relationship modelling (entities, attributes, relationships and cardinality) and normalisation to first, second and third normal form to remove redundancy and anomalies.
- System modelling with data flow diagrams and UML diagrams (use case, class and activity), and the role of the data dictionary.
A CCEA A-Level Software Systems Development answer on system modelling: data flow diagrams showing processes and data stores, and UML diagrams (use case, class and activity), plus the data dictionary, and why models are used.
- The stages of the systems development lifecycle - analysis, design, implementation, testing, installation and maintenance - and the purpose of a structured approach.
A CCEA A-Level Software Systems Development answer on the systems development lifecycle: the stages of analysis, design, implementation, testing, installation and maintenance, what happens in each, and why a structured approach is used.
Sources & how we know this
- CCEA GCE Software Systems Development specification — CCEA (2016)