This study notes covers Practical SQL Query Examples within SQL for GCSE Computer Science. Revise SQL in Programming for GCSE Computer Science with 15 exam-style questions and 10 flashcards. This topic appears regularly enough that it should still be part of a steady revision cycle. It is section 6 of 8 in this topic. Use this study notes to connect the idea to the wider topic before moving on to questions and flashcards.
Topic position
Section 6 of 8
Practice
15 questions
Recall
10 flashcards
Practical SQL Query Examples
Given this Students table:
| StudentID | Name | Age | City | Score |
|---|---|---|---|---|
| 1 | Alice | 15 | London | 85 |
| 2 | Bob | 17 | Manchester | 72 |
| 3 | Charlie | 16 | London | 91 |
| 4 | Diana | 17 | Leeds | 68 |
| 5 | Eve | 15 | London | 95 |
Query 1: All London students
SELECT Name, Age FROM Students WHERE City = "London" -- Returns: Alice (15), Charlie (16), Eve (15)
Query 2: Students aged 16+ sorted by score (highest first)
SELECT Name, Score FROM Students WHERE Age >= 16 ORDER BY Score DESC -- Returns: Charlie (91), Bob (72), Diana (68)
Query 3: London students with score over 90
SELECT * FROM Students WHERE City = "London" AND Score > 90 -- Returns: Charlie (91), Eve (95)
Query 4: Students from London OR Manchester
SELECT Name, City FROM Students WHERE City = "London" OR City = "Manchester" -- Returns: Alice, Bob, Charlie, Eve