GCSE · Computer Science · OCR · Spec J277
SQL: SELECT, FROM, WHERE
A database can hold thousands of records and you want four of them. SQL asks for exactly those four, using three keywords.
Two queries, one table
Watch a query cut the table down
Two queries, one table of music tracks. Each press of Next shows what is left after one more part of the query has done its job.
Before each Next, predict what will be left.
SELECT Title, Plays FROM tblTracks WHERE Genre = "Rock"; SELECT Title, Artist FROM tblTracks WHERE Plays > 300;
Result
| Title | Artist | Genre | Plays |
| Paper Moon | The Springs | Pop | 420 |
| Static | Iron Gate | Rock | 310 |
| Lemon Sky | The Springs | Rock | 150 |
| Night Bus | Mia Cole | Pop | 95 |
| Echo | The Springs | Pop | 260 |
| Gravel | Iron Gate | Rock | 500 |
Output
Step 1: Query 1. FROM tblTracks names the table: six records (rows), four fields (columns). Which tracks do you think will survive WHERE Genre = "Rock"?
Cover the result with your hand, predict, then press Next.
Predict, then check
A table tblDownloads logs the Time of each download. The query is SELECT * FROM tblDownloads WHERE Time BETWEEN "06:00" AND "07:00";
One download was logged at exactly 07:00. Does this query return it?
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
Three keywords, three jobs: pick the columns, name the table, choose the rows.
What you need to know
- SQL stands for Structured Query Language: you use it to search, retrieve, insert, delete and update records in a database.
- SELECT is followed by the field names (columns) you want to display, separated by commas.
- FROM is followed by the name of the table those fields come from.
- WHERE is followed by the criteria a record must meet to be returned, such as WHERE Genre = "Rock".
Have a goIn SELECT Title FROM tblTracks WHERE Artist = "Iron Gate"; which part decides the rows you get back, and which decides the columns?
WHERE decides the rows; SELECT decides the columns (just Title).
SELECT sounds as if it picks the records, but it only chooses which fields appear; the WHERE criteria decide which records make it.
- Text you are searching for goes in speech marks, and the statement ends with a semicolon.
- Comparison operators: equal to (=), greater than (>), less than (<), greater or less than or equal to (>=, <=), and not equal to.
Have a goYour friend Jas swears WHERE Plays > 300 and WHERE Plays >= 300 always give exactly the same records. Find the one kind of record that proves Jas wrong.
A record with exactly 300 plays: >= keeps it, > drops it.
Greater than on its own leaves out the value itself; "or equal to" is what lets 300 in, so the two only differ at that exact value.
- AND is true only if both conditions are true; OR is true if any of the conditions is true.
Have a goA table has 4 Pop tracks and 3 Rock tracks, and no track is both. How many records does WHERE Genre = "Pop" OR Genre = "Rock" return?
7
OR keeps a record if any condition is true, so every Pop track and every Rock track comes back; reading OR as "pick one of the groups" gives 4 or 3.
- BETWEEN is true when a value is within the stated range, and the two end values count.
- SELECT * returns every field in the table, so save it for when you need all of them.
The big picture
SQL (Structured Query Language) is used to communicate with a database. In a query, SELECT lists the fields to show, FROM names the table, and WHERE gives the criteria a record must meet. Comparison operators and the logical operators AND, OR and BETWEEN make the criteria more precise.
Key points
Worked example
Problem
Using tblTracks (Title, Artist, Genre, Plays), write a query to show the Title and Genre of every Iron Gate track with more than 400 plays.
⚠ Watch out
Leaving the speech marks off text. WHERE Genre = Rock looks fine at a glance, but the text being searched for must be in speech marks: WHERE Genre = "Rock"; and the statement ends with a semicolon.
Memory hook
Columns, table, rows: SELECT, FROM, WHERE, in that order. Then AND squeezes, OR spreads: adding an AND condition can never give you more records, and adding an OR condition can never give you fewer.
Check yourself
Cover the page. Say what SELECT, FROM and WHERE each choose. Then write a query for the Artist of every Pop track in tblTracks with fewer than 300 plays, and say which tracks it returns.
Flashcards
(13)What does SQL stand for?
Four things SQL can do with records
What follows the keyword SELECT?
What follows the keyword FROM?
What follows the keyword WHERE?
How do you write text you are searching for?
How does an SQL statement end?
What does SELECT * return?
When should you use SELECT *?
Name the six comparison operators
When is AND true?
When is OR true?
Does BETWEEN include the end values?
Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.
Learning with Lightbulb is opening soon
You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.
Keep me postedMore OCR GCSE Computer Science topics
How this lesson was checked. This OCR GCSE Computer Science (specification J277)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 3 November 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.