GCSE · Computer Science · AQA · Spec 8525
SQL DELETE
One tiny word, OR instead of AND, can quietly wipe out members you never meant to touch. Here is how a DELETE decides who goes.
Computer Science · Databases
Who gets deleted? Test every record
Commit to a prediction, then step through tblMembers one record at a time: both AND pairs first, then the OR.
Before you press Next: which records of tblMembers will this statement delete? Test each record against the two AND pairs, then the OR.
DELETE FROM tblMembers WHERE Firstname = "Abla" AND Surname = "Baroni" OR Firstname = "Nadim" AND Surname = "Abe";
Result
| MemberID | Firstname | Surname | Verdict |
|---|---|---|---|
| 1 | Abla | Baroni | not tested |
| 2 | Abla | Okafor | not tested |
| 3 | Priya | Baroni | not tested |
| 4 | Nadim | Abe | not tested |
| 5 | Nadim | Khan | not tested |
| 6 | Chen | Abe | not tested |
| 7 | Zara | Lindqvist | not tested |
Output
Step 1: Here is tblMembers before the DELETE runs. For each record, test the first AND pair, then the second AND pair. If either pair is wholly true, the OR is true and that record is deleted. Press Next to test record 1.
Step with Next and decide each record yourself before you read the note.
Predict, then check
Brackets change who gets caught. Decide before you reveal.
tblMembers holds: 1 Nadim Abe, 2 Abla Abe, 3 Abla Baroni, 4 Nadim Khan, 5 Chen Abe (MemberID, Firstname, Surname). DELETE FROM tblMembers WHERE Surname = "Abe" AND (Firstname = "Nadim" OR Firstname = "Abla"); Which records does it delete?
Computer Science · Databases
Which command does the job?
Sort each database task under the SQL command that does it.
Still to sort
SELECT (0)
Searches for and retrieves records
Where the line is: SELECT only retrieves data; it does not add, change or remove any record.
INSERT (0)
Inserts new records
Where the line is: INSERT adds a record that was not there before.
UPDATE (0)
Updates existing records
Where the line is: UPDATE changes a record that stays in the table; DELETE removes it.
DELETE (0)
Deletes existing records
Where the line is: DELETE removes a record from the table.
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
One small word in the criteria decides which members disappear.
What you need to know
- SQL (structured query language) manages data in relational databases, using standardised commands that must follow the right syntax to run.
- Four common jobs: SELECT retrieves records, INSERT adds new ones, UPDATE changes existing ones, and DELETE removes them.
- To delete existing records, write DELETE FROM table WHERE criteria.
Have a goYour classmate Jas types DELETE tblMembers WHERE Surname = "Abe"; and swears it is perfect. Which word has Jas left out?
FROM: it should be DELETE FROM tblMembers WHERE Surname = "Abe";
The basic syntax is DELETE FROM table WHERE criteria, and a statement that breaks the syntax rules will not execute correctly.
- The WHERE clause gives the criteria for which records are deleted.
- Need more than one condition? Join them with AND or OR, and don't write WHERE again.
Have a gotblMembers has 3 members called Abla and 2 called Nadim, and nobody is both. How many records does WHERE Firstname = "Abla" OR Firstname = "Nadim" catch?
5 records.
OR catches a record that meets either condition, so you add the groups together; it is not a choice of just one of them.
- AND is evaluated before OR, just as multiplication comes before addition in arithmetic.
Have a goIn WHERE Firstname = "Nadim" OR Firstname = "Abla" AND Surname = "Abe", which two conditions are joined together first?
Firstname = "Abla" AND Surname = "Abe".
AND is evaluated before OR, like 3 × 4 before adding 2 in 2 + 3 × 4, so reading left to right is the tempting mistake.
- Brackets can make your intention clearer by grouping conditions together.
- Criteria that are missing or too broad delete more records than intended; with no WHERE clause, every record is deleted.
The big picture
The SQL DELETE statement removes existing records from a table, and its basic syntax is DELETE FROM table WHERE criteria. The WHERE clause gives the criteria for which records are deleted; more conditions are added with AND and OR, and AND is evaluated before OR, as multiplication comes before addition. Brackets can make the intention clearer. A DELETE without suitable criteria deletes more records than intended, and with no WHERE clause it deletes every record in the table.
Key points
Worked example
Problem
tblMembers holds: 1 Priya Chen, 2 Priya Okafor, 3 Leo Chen, 4 Zara Lindqvist (MemberID, Firstname, Surname). Priya Chen has left the club. Write a DELETE statement that removes only her record, then check which records it deletes.
⚠ Watch out
Reading AND and OR from left to right, or leaving the criteria loose. In WHERE A AND B OR C AND D the two AND pairs are checked first, and with no WHERE clause at all every record is deleted.
Memory hook
AND ties first, like times beats plus. Read the pairs, then the OR. And before any DELETE, ask which records the WHERE clause catches.
Check yourself
Cover the page. Say what each part of DELETE FROM tblMembers WHERE Firstname = "Mia" AND Surname = "Chen"; does, and what kind of extra record would be deleted if the AND were an OR.
Flashcards
(9)What does SQL do?
Basic syntax of the SQL DELETE statement
What does the WHERE clause decide in a DELETE?
How do you set more than one criterion in a WHERE clause?
AND and OR in one WHERE clause: which is evaluated first?
What can brackets do in a WHERE clause?
What happens if a DELETE has no suitable criteria?
Which SQL command retrieves records, and what does SELECT * return?
Which SQL commands add new records and change existing ones?
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 AQA GCSE Computer Science topics
How this lesson was checked. This AQA GCSE Computer Science (specification 8525)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 4 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.