SLIDE 1
CSZone.co.uk
Click to advance · Arrow keys also work
Cambridge IGCSE 0478 · Topic 9 · 9.2

SQL

SELECT · FROM · WHERE · AND / OR · ORDER BY · Wildcards

CSZoneCambridge IGCSE Computer Science 0478
Basic SELECT Query

Retrieving Data from a Table

SQL (Structured Query Language) is used to query and manipulate relational databases. For Cambridge 0478, you need to write SELECT queries to retrieve data.
-- Select all fields from Students table
SELECT *
FROM Students;

-- Select specific fields only
SELECT Name, Age
FROM Students;

-- SELECT * means "all columns"
-- Always end SQL statements with a semicolon
WHERE Clause & Logical Operators

Filtering Records

-- Students aged 16
SELECT Name, Age
FROM Students
WHERE Age = 16;

-- Students aged 15 OR 16
SELECT Name FROM Students
WHERE Age = 15 OR Age = 16;

-- Students in Form 10A AND aged 15
SELECT * FROM Students
WHERE Form = "10A" AND Age = 15;

-- Students NOT aged 15
SELECT * FROM Students
WHERE NOT Age = 15;
ORDER BY & Wildcards

Sorting & Pattern Matching

-- Sort alphabetically by Name (A-Z = ASC)
SELECT Name, Age FROM Students
ORDER BY Name ASC;

-- Sort by Age descending (highest first)
SELECT * FROM Students
ORDER BY Age DESC;

-- Wildcard: find names starting with "A"
SELECT * FROM Students
WHERE Name LIKE "A%";

-- % matches any number of characters
-- _ matches exactly one character
LIKE is used for pattern matching: LIKE "Sm%" matches Smith, Smiley; LIKE "J_n" matches Jan, Jon
Exam Practice

Have a go at this question

Cambridge IGCSE 0478 style
A database table called Books has fields: ISBN, Title, Author, Year, Price. Write SQL to retrieve the Title and Author of all books published after 2010 that cost less than £15, sorted by Price in ascending order.
4 marks
SELECT Title, Author
FROM Books
WHERE Year > 2010 AND Price < 15
ORDER BY Price ASC;
Key Takeaways

What to Remember

SELECT fields FROM table — use * for all fields; always specify table after FROM
WHERE: filter records; AND (both), OR (either), NOT (reverse); strings in double quotes
ORDER BY field ASC/DESC — ASC = A→Z or lowest first; DESC = Z→A or highest first
LIKE with wildcards: % = any characters; _ = exactly one character — for pattern matching