SQL queries Cambridge IGCSE Computer Science (9–1) revision
Not started
Learn it
In plain words
Structured query language (SQL) is how you ask a database a question. A query reads almost like a sentence: select these fields, from this table, where this is true, in this order.
6 things to know
- SELECT lists the fields to be shown. FROM names the table.
- WHERE gives the condition a record must meet to be included. Conditions can be joined with AND (both must be true) or OR (at least one must be true).
- ORDER BY sorts the results by a field: ASC for ascending order and DESC for descending order.
- SUM adds up the values in a field. COUNT counts the number of records.
- The order of the parts never changes: SELECT, FROM, WHERE, ORDER BY.
- Text values in a condition go inside quotation marks. Numbers do not.
Worked example
A table called Books has the fields Title, Genre and Price. It holds: Night Sky, Science, 12.50. Lost Map, Adventure, 7.99. Deep Sea, Science, 9.00. Iron Gate, Crime, 7.50. What is the output of SELECT Title FROM Books WHERE Price < 10 ORDER BY Price ASC?
- WHERE Price < 10 keeps the books that cost less than 10: Lost Map (7.99), Deep Sea (9.00) and Iron Gate (7.50).
- ORDER BY Price ASC puts them in order of price, cheapest first: 7.50, 7.99, 9.00.
- SELECT Title shows only the titles: Iron Gate, Lost Map, Deep Sea.
Tips and tricks
- Only the fields after SELECT are shown. A field used in WHERE or ORDER BY does not appear unless it is also selected.
- Work in this order: apply WHERE to choose the records, then ORDER BY to sort them, then SELECT to pick the fields.
It lands in your notebook with its questions as flashcards.
SQL queries: 6 questions and answers
These are the quiz’s questions. Do the quiz first, then come back here for the ones that got you.
Which SQL keyword lists the fields to be displayed?
SELECT comes first in every query.
Which SQL keyword names the table to search?
FROM Books, for example.
Which SQL keyword sets the condition that records must meet?
Only records that meet the condition are included.
What does ORDER BY Price DESC do?
DESC means descending.
What does COUNT do in an SQL query?
SUM is the one that adds up.
Which records does WHERE Age > 15 AND House = 'Red' select?
With AND, both conditions must be true.
Quiz
6 questions
Tap an answer and you’ll see straight away whether it’s right, and why.
Worksheet
2 questions, 5 marks. Write your answers on paper, then check them.
SQL queries
Cambridge IGCSE Computer Science (9–1) 0984 · 5 marks · papermunch.org
Name ______________________________ Date ______________
Using the Books table above, write an SQL query to show the title and price of every Science book.[3]
Show answerHide answer
SELECT Title, Price FROM Books WHERE Genre = 'Science'
Using the Books table above, state the output of SELECT COUNT(Title) FROM Books WHERE Genre = 'Science' and of SELECT SUM(Price) FROM Books WHERE Genre = 'Science'.[2]
Show answerHide answer
The count is 2. The sum is 21.50.
Answers: SQL queries
- 1. SELECT Title, Price FROM Books WHERE Genre = 'Science'
- 2. The count is 2. The sum is 21.50.



