Skip to main content
Northern IrelandDigital TechnologySyllabus dot point

How are data queried, inserted and updated using SQL and query by example?

Using a database through Structured Query Language (SELECT, INSERT, UPDATE, DELETE) and query by example, including selecting, sorting and joining data.

A CCEA A-Level Digital Technology answer on using a database with Structured Query Language: SELECT, INSERT, UPDATE and DELETE, filtering, sorting and joining tables, and the query by example alternative.

Generated by Claude Opus 4.811 min answer

Reviewed by: AI editorial process; not yet individually human-reviewed

Have a quick question? Jump to the Q&A page

Jump to a section
  1. What this dot point is asking
  2. Selecting data with SQL
  3. Inserting, updating and deleting
  4. Joining tables
  5. Summarising data
  6. Query by example
  7. Try this

What this dot point is asking

CCEA wants you to use a database through Structured Query Language (SELECT, INSERT, UPDATE, DELETE) and through query by example, including selecting, filtering, sorting and joining data. This is the practical side of databases: getting data in, out and changed.

Selecting data with SQL

A basic query names the columns, the table, an optional filter and an optional sort:

SELECT Surname, Town
FROM Students
WHERE Year = 13
ORDER BY Surname;

This returns the surname and town of Year 13 students, sorted alphabetically. Using SELECT * returns all columns, which is convenient but wasteful when only some are needed.

Inserting, updating and deleting

INSERT INTO Students (StudentID, Surname, Year, Town)
VALUES (1024, 'Kelly', 13, 'Bangor');

UPDATE Students
SET Town = 'Newtownards'
WHERE StudentID = 1024;

DELETE FROM Students
WHERE StudentID = 1024;

Joining tables

Because data is split across normalised tables, queries often need a JOIN to combine them on a matching key:

SELECT Students.Surname, Bookings.BookingDate
FROM Students
JOIN Bookings ON Students.StudentID = Bookings.StudentID
WHERE Bookings.BookingDate = '2026-06-16';

This links each booking to the student who made it by matching the foreign key in Bookings to the primary key in Students. A JOIN is needed precisely because normalisation splits related data across tables; without it, a query could only see one table at a time.

Summarising data

SQL can also summarise rather than just list. Aggregate functions such as COUNT, SUM, AVG, MAX and MIN calculate a single value over many rows, and GROUP BY produces one result per group:

SELECT Town, COUNT(*) AS NumberOfStudents
FROM Students
GROUP BY Town;

This counts how many students live in each town, returning one row per town. Aggregate queries turn raw records into the kind of summary information a manager actually wants, which is why they are examined alongside the basic SELECT.

Query by example

Query by example (QBE) is a visual alternative to SQL. The user is shown a grid of the fields and enters criteria under the columns they want (for example "13" under Year and a sort order under Surname); the database then builds and runs the underlying query. QBE is easier for non-technical users because no syntax must be memorised, while SQL is more precise, more powerful for complex queries, and can be saved and embedded in programs.

Try this

Q1. Write an SQL statement to return all columns of the Books table where Genre is 'Science'. [2 marks]

  • Cue. SELECT * FROM Books WHERE Genre = 'Science';

Q2. State which SQL keyword sorts the results of a query. [1 mark]

  • Cue. ORDER BY.

Q3. Explain why a DELETE statement should normally include a WHERE clause. [2 marks]

  • Cue. The WHERE clause selects which records to remove; without it, DELETE removes every record in the table, causing unintended data loss.

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 A2 14 marksA table Students has fields StudentID, Surname, Year and Town. Write an SQL query to list the surname and town of all students in Year 13, sorted by surname.
Show worked answer →

Use SELECT with a WHERE filter and an ORDER BY clause.

SELECT Surname, Town
FROM Students
WHERE Year = 13
ORDER BY Surname;

The SELECT clause names the columns to return, FROM names the table, WHERE filters to Year 13 only, and ORDER BY sorts the results by surname (ascending by default).

Markers award marks for the correct SELECT of the two named fields, the correct WHERE condition, and the ORDER BY clause. Selecting all fields with an asterisk when only two are asked for, or omitting the WHERE filter, loses marks. Quoting the number 13 as text is also penalised because Year is numeric.

CCEA A2 15 marksExplain the difference between SQL and query by example (QBE), and state one advantage of each.
Show worked answer →

Contrast how the user expresses the query, then give an advantage of each.

SQL (Structured Query Language) is a text-based language: the user types commands such as SELECT, INSERT, UPDATE and DELETE to manipulate data. Query by example (QBE) is a visual approach: the user fills in a grid, entering criteria under the relevant fields, and the system builds the query for them.

Advantage of SQL: it is precise and powerful, can express complex queries and joins, and can be saved and reused in programs. Advantage of QBE: it is easier for non-technical users because no syntax must be memorised; the user picks fields and types criteria into a form.

Markers reward the text-versus-visual contrast and a valid advantage of each. Saying QBE is "just SQL with pictures" without the no-syntax benefit, or claiming SQL is always easier, limits the marks.

Related dot points

Sources & how we know this