Ask the database questions. SELECT, FROM, WHERE, ORDER BY — the four clauses that carry every Cambridge database question from 2022 to today.
In Lab A you learned how a database is shaped. In Lab B you learn how to ask it questions. Every SQL query you write from now on is one sentence in three parts: SELECT picks the columns you want, FROM names the table, WHERE filters down to only the records that match your condition, and ORDER BY sorts the results the way you want to see them.
The reason we're teaching these three lessons together (not one at a time) is that Cambridge always tests them together. Every single Paper 2 database question from 2022 to 2026 combines at least two of these clauses in one query — often all three. Learning them in isolation is how students lose exam marks. Learning them as one sentence is how you keep them.
Before you start: you need the vocabulary from Lab A — fields, records, data types, primary keys. If any of those feel shaky, jump back for five minutes.
SELECT ... FROM to return one or more fields from a table.SELECT are returned in the order given, separated by commas.SELECT ... FROM ... WHERE to return only records that meet a condition.=, <>, <, <=, >, >=.AND and OR to combine multiple conditions.WHERE do not have to appear in SELECT.ORDER BY to sort results.ASC, the default) from descending (DESC).ORDER BY correctly — it always comes after WHERE, at the end of the statement.| Term | Meaning |
|---|---|
| Query | A single SQL request made to a database to return specific data. |
SELECT | The SQL keyword that specifies which fields (columns) to return. |
FROM | The SQL keyword that specifies which table to query. |
WHERE | The SQL keyword that specifies a condition — only records matching the condition are returned. |
ORDER BY | The SQL keyword that sorts the returned records. |
ASC | Sort order keyword: ascending (smallest to largest, A to Z). This is the default if you don't say. |
DESC | Sort order keyword: descending (largest to smallest, Z to A). Must be written explicitly. |
| Logical operator | A symbol that performs a comparison and returns True or False: =, <>, <, <=, >, >=. |
| Boolean operator | A word that joins multiple conditions: AND, OR. |
| Condition | The comparison used in a WHERE clause — always a field, an operator, and a value (e.g. Cost < 3.99). |
; (semi-colon) | The character that ends an SQL statement. Cambridge past papers always show it. |
SQL keywords are conventionally written in UPPERCASE (SELECT, FROM, WHERE). Cambridge mark schemes accept lowercase too, but UPPERCASE is the exam-safe habit — it visually separates keywords from field names.
Every query is the same skeleton:
SELECT <fields> FROM <table> WHERE <condition> ORDER BY <field> [ASC | DESC];
WHERE must come before ORDER BY.;.Rule of thumb: if a question tells you to "list", "display", or "output" records, the query starts with SELECT.
Fields listed in SELECT are returned in the order given, separated by commas. Same data, different query = different output columns.
SELECT BookName, Author FROM Books;
Output:
Picking daisies J. Frank
Night stars K. Mars
SELECT Author, BookName FROM Books;
Output:
J. Frank Picking daisies
K. Mars Night stars
The order in the query determines the order in the answer.
SELECT — never after the last field, never between FROM and the table name.SELECT * — but the Cambridge syllabus does not teach *. Always list the fields explicitly.Straight from the textbook: "The case, spellings and order are all important. If the field name in the table is Genre then putting genre in the query is incorrect."
Genre in the table → your query must say Genre exactly.BookList → your query must say BookList exactly.One exception: SQL keywords (SELECT, FROM, WHERE) are accepted in any case, but write them UPPERCASE anyway for clarity.
Present as a single reference. This is the workhorse of exam questions.
| Operator | Meaning | Example |
|---|---|---|
= | Equal to | WHERE Fiction = TRUE |
<> | Not equal to | WHERE Cost <> 4.00 |
< | Less than | WHERE Cost < 3.99 |
<= | Less than or equal to | WHERE Cost <= 10 |
> | Greater than | WHERE Quantity > 0 |
>= | Greater than or equal to | WHERE Quantity >= 100 |
Anchor point: these are the same comparison operators you met in Chapter 8 (Programming). Same symbols, same meaning. The only difference is that SQL doesn't use != — the "not equal to" operator in SQL is <>.
This subsection is worth more marks per exam than any other single rule in Topic 9. The evidence base is overwhelming: 2023, 2024 s24, 2024 w24, 2025 w25 examiner reports all flag it.
| Data type of value | Quotes in SQL? | Example |
|---|---|---|
| Text | Yes — double or single | WHERE Country = "China" or WHERE Country = 'China' |
| Character | Yes | WHERE Grade = 'A' |
| Integer | No | WHERE Population > 1000000 |
| Real | No | WHERE Cost <= 3.99 |
| Boolean | No — this is the trap | WHERE Capital = TRUE |
| Date/Time | Yes (treated like text) | WHERE Date = "11/12/2019" |
Cambridge mark schemes accept both single and double quotes on strings — pick one and be consistent. Never put quotes around a Boolean or a number.
"If it's text-like, quote it. If it's number-like or True/False, don't."
You can filter on more than one condition by joining conditions with AND or OR.
| Operator | Effect |
|---|---|
AND | Only records that meet both conditions are returned. |
OR | Records that meet either condition are returned. |
Syllabus note: the Cambridge specification lists AND and OR only. NOT is not required for this syllabus — leave it aside.
ORDER BY <field> sorts on that field.ASC, but it's not wrong to.ORDER BY <field> DESC.ORDER BY always comes after WHERE, at the end of the statement.Ascending on numbers = smallest first. Descending on numbers = largest first. Ascending on text = A first, Z last. Descending on text = Z first, A last.
The 2025 s25 MajorCity trap: if the question asks for cities in South America sorted by population, the WHERE filters the continent AND the ORDER BY sorts what's left. A common wrong answer put cities in the wrong order — students filtered correctly but sorted by the wrong field or in the wrong direction.
All eight examples use the MajorCity table from Cambridge 2025 s25. Same data across every example — the query is what changes.
Code City Capital Country Continent Population ASY6 Abu Dhabi TRUE UAE Asia 1,566,999 EUY3 Amsterdam TRUE Netherlands Europe 1,174,025 ASY1 Beijing TRUE China Asia 21,766,214 SAY1 Buenos Aires TRUE Argentina South America 15,490,415 AFY1 Cairo TRUE Egypt Africa 22,183,200 EUN1 Frankfurt FALSE Germany Europe 796,437 ASY3 Jakarta TRUE Indonesia Asia 11,248,839
SELECT City FROM MajorCity;
Returns: every city name, in the order they appear in the table (no sort applied).
Teaching point: no WHERE = all records. No ORDER BY = original order.
SELECT City, Population FROM MajorCity; SELECT Population, City FROM MajorCity;
Same data, different column order. Students who reverse the fields lose marks.
SELECT City, Population FROM MajorCity WHERE Continent = "Asia";
Returns: Abu Dhabi 1566999, Beijing 21766214, Jakarta 11248839.
Teaching point: "Asia" is Text — quotes required. Miss the quotes = zero marks on this line (cited: 2025 w25 examiner report).
SELECT City FROM MajorCity WHERE Population > 10000000;
Returns: Beijing, Buenos Aires, Cairo, Jakarta.
Teaching point: 10000000 is Integer — no quotes. Writing Population > "10000000" is marked wrong even if some databases accept it.
SELECT City, Country FROM MajorCity WHERE Capital = TRUE;
Returns: every city where Capital is TRUE.
Teaching point: Boolean values are never quoted. WHERE Capital = "TRUE" is a mark-loser. The most-cited SQL exam mistake.
SELECT City, Population FROM MajorCity WHERE Continent = "Asia" AND Population > 5000000;
Returns: Beijing (21.7M), Jakarta (11.2M). Abu Dhabi is filtered out — it's Asian but only 1.5M.
Teaching point: AND = both must be true. Every record is checked against both conditions.
SELECT City, Population FROM MajorCity ORDER BY Population;
Returns: every city, listed smallest population to largest. ASC is implied.
SELECT City, Country, Population FROM MajorCity WHERE Continent = "South America" ORDER BY Population DESC;
Returns: Buenos Aires 15490415 (the only South American city in our sample). If more existed, they'd be sorted largest to smallest.
The full-query rule: SELECT → FROM → WHERE → ORDER BY → ;. Every clause on its own line. ORDER BY always after WHERE. Semi-colon at the end.
❌ Writing WHERE Country = China instead of WHERE Country = "China"
Text values in WHERE conditions must be in quotation marks (single or double, Cambridge accepts either). Without quotes the database treats the value as a field name — and if no field called "China" exists, the query fails. This is the single most-cited SQL mistake across Cambridge examiner reports 2023–2025.
Cited: 2023 Q9 BookList — "not to include quotation marks round the required author's name." · 2024 s24 Q9 SoftDrinks — "did not put quotation marks around 'Can' in the WHERE statement." · 2025 w25 — "missing off the quotation marks around the search criteria 'Asia'."❌ Writing WHERE Capital = "TRUE" or WHERE Population > "1000000"
Booleans and numbers are never quoted in SQL. Only text-like values (Text, Character, Date/Time) get quotes. Writing "TRUE" turns a Boolean into a text string — and some databases won't match it against the actual Boolean value in the table.
WHERE Capital = TRUE (no quotes).
❌ Adding a comma after the last field, adding punctuation inside SELECT, or ending a line mid-clause
SELECT City, Country, (trailing comma) is a syntax error. SELECT City. Country (period instead of comma) is a syntax error. Cambridge examiner reports flag "extra punctuation" as a recurring mark loss.
❌ Adding commas or full stops when writing out what a query returns
When asked to "write the output of this SQL statement", students often add commas between the returned values. Cambridge outputs are plain values, one record per line, separated only by spaces or tabs — never punctuation.
Cited: 2024 w24 — "Punctuation marks should not be in the output from an SQL statement." · Reinforced 2025 m25 — same wording.❌ Writing a field name that sounds right but isn't actually the field the question asks for
The 2024 w24 examiner report flagged Airworthy as a common incorrect field in the SELECT line — students picked a nearby field instead of reading the question. Always re-check: which fields does the question actually ask for?
❌ Writing ORDER BY City when the question asked to sort by population, or writing ASC when DESC was needed
Read the question carefully — "ascending" vs "descending", "alphabetical" vs "numerical", and which field to sort on.
Cited: 2025 s25 Q8 MajorCity — "rows being sorted in the wrong order, for example, with Buenos Aires being in the first row rather than Valencia."❌ Writing SELECT genre FROM Books when the field is Genre
SQL field names and table names are case-sensitive. If the table shows BookName, your query must say BookName — not bookname, not Book_Name, not Book Name. Copy the field name exactly as it appears.
❌ Writing SELECT ... FROM ... ORDER BY ... WHERE ...
The clause order is fixed: SELECT → FROM → WHERE → ORDER BY. If both are used, WHERE must come first. Reversing them is a syntax error.
Mark-scheme-phrased chips. The exam-safe habits.
"China" yes. TRUE yes. "TRUE" no. "3.99" no."double" and 'single' quotes on Text and Character values. Pick one and stay consistent within a query.; — every Cambridge past-paper SQL example does. Missing it may lose the mark; including it never hurts.SELECT → FROM → WHERE → ORDER BY. Never rearrange.Genre ≠ genre.SELECT * in this syllabus. Always list the fields explicitly, even if you want all of them.ASC is the default — writing it explicitly is fine but not required. DESC must always be written.<> is "not equal to" — SQL does not use !=. That's a programming operator, not an SQL one.WHERE don't have to appear in SELECT. You can filter on Continent without displaying Continent.AND and OR only — no NOT in this specification.Click each question to reveal the answer.
SELECT (which fields), FROM (which table), and a ; at the end. WHERE and ORDER BY are optional.SELECT clause, and is it needed after the last field?WHERE Country = "China", why is China in quotation marks?China is a Text value, and Text values must be quoted in SQL.WHERE Capital = TRUE, why is TRUE NOT in quotation marks?TRUE is a Boolean value, and Booleans are never quoted in SQL.WHERE clauses?= (equal to), <> (not equal to), < (less than), <= (less than or equal to), > (greater than), >= (greater than or equal to).ORDER BY if you don't specify?ASC). You don't need to write it — but writing it doesn't cost marks.SELECT → FROM → WHERE → ORDER BY → ;. WHERE always comes before ORDER BY.SELECT City, Country FROM MajorCity WHERE Continent = "Asia" AND Capital = TRUE ORDER BY Population DESC;Key checks:
"Asia" quoted (Text), TRUE unquoted (Boolean), DESC explicit, ORDER BY after WHERE, ; at the end.You can now write a complete SQL query. You know what SELECT, FROM, WHERE, and ORDER BY do, when to use quotes, and what order the clauses go in. This is the core skill Cambridge tests every year.
Next lab: 9.6–9.7 Aggregating Lab — where you learn the two functions that let SQL do maths for you: SUM (adds up a field) and COUNT (counts records). Same query skeleton you've just learned — plus one extra bit of syntax. See you in Lab C.
Book Notes is the reference. Learn is the walk-through. If SQL is new, start here and go slow. If Book Notes already clicked, skim.
Every SQL query you'll ever write in this syllabus is one sentence built from up to four fixed parts, in this fixed order:
SELECT which columns FROM which table WHERE which records (optional) ORDER BY how to sort them (optional)
SELECT and FROM. Every query has these two.WHERE filters records. ORDER BY sorts them.WHERE comes before ORDER BY. Always.The database does the same. It picks the table (FROM), filters the records (WHERE), sorts them (ORDER BY), then picks the columns to show (SELECT). You write it in exam order; the database executes it in that logical order.
Fields listed in SELECT are returned in the exact order you write them, separated by commas.
SELECT City, Country gives you the city first, then the country.
SELECT Country, City flips it — country first, then city. Same data, wrong column order = lost marks.
Comma rules:
FROM and the table name.SELECT *. Always list fields explicitly.Vocabulary lock: in databases, columns are called fields. When the question says "output the fields", it means "show these columns".
WHERE narrows the table down. Every WHERE clause has the same shape: field · operator · value. Example: WHERE Cost < 3.99.
The trap is on the value. Whether it takes quotes depends entirely on its data type:
Quote it: Text, Character, Date/Time.WHERE Country = "China". WHERE Grade = 'A'.
Don't quote: Integer, Real, Boolean.WHERE Price > 5. WHERE Capital = TRUE.
"If the value is text-like, quote it. If it's number-like or True/False, don't." This rule alone is worth more exam marks than any other in Topic 9.
Two conditions? Join them with AND (both must match) or OR (either matches). Cambridge doesn't test NOT in this syllabus.
ORDER BY takes two pieces of information: which field to sort on, and which direction.
ASC) is the default. Small → large. A → Z. You don't have to write ASC, but you can.DESC) is the opposite. Large → small. Z → A. You must write it explicitly.Placement: always last, always after WHERE if WHERE is present. Put ORDER BY in the middle and the query breaks.
Cambridge questions bury the sort direction in a phrase. "Highest to lowest" → DESC. "In alphabetical order" → ASC. "Youngest first" (biggest DOB numeric) → DESC. Every year, students lose the mark by defaulting to ASC when the question wanted DESC.
Time to write real queries at Query Bench — a live SQL playground where the database runs your query, shows the rows it returns, and lints the exam-critical rules.
Pick a scenario, read the brief, then write the SQL to answer it. The bench runs your query against a live sample table, shows you the rows it returns, and lint-checks it against the Cambridge mark scheme rules that examiners cite every sitting.
Run your query to see the rows it returns.
Feedback lands here after you run — mark-scheme-style checks on quoting, clause order, spelling, and matched rows.
SELECT → FROM → WHERE → ORDER BY. Reversing any pair is a syntax error.Multiple-choice checks. Start on Easy if you're new to the topic; move up as you go. Every attempt is logged in Progress.
Real past-paper style. Type your answer, then self-mark against the mark scheme. Skills feed into Mastery.
Your mistakes, ranked by frequency. The Vault fills up as you Save from Practice and Exam.
No mistakes logged yet. Come back after Practice and Exam.
Nothing in the Vault yet. Save key facts from Book Notes or from question feedback.
Every skill you attempt (in Query Bench, Practice, or Exam) is scored. Get 3+ attempts with 70%+ accuracy on a skill and it goes green — mastered.
No attempts yet.
Complete Practice and Exam to unlock achievements.
No bookmarks yet. Star a question in Practice or Exam to save it here.