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

MemberIDFirstnameSurnameVerdict
1AblaBaroninot tested
2AblaOkafornot tested
3PriyaBaroninot tested
4NadimAbenot tested
5NadimKhannot tested
6ChenAbenot tested
7ZaraLindqvistnot 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.

1 / 9

Step with Next and decide each record yourself before you read the note.

Step 1 of 9: 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..

Exam line: In a WHERE clause, AND pairs are evaluated before OR; a record is deleted if it meets the criteria.
Watch out: Matching just a first name or just a surname is not enough: an AND pair needs both of its conditions true.

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

Delete only Nadim Abe

tblMembers holds: 1 Nadim Abe, 2 Chen Abe, 3 Nadim Khan, 4 Abla Baroni, 5 Zara Okafor. The task: delete only the member Nadim Abe. Find the line where this answer goes wrong.

A student's answer — which line goes wrong?

Exam line: Join the conditions that must both be true with AND; OR widens the criteria and deletes more records.

Computer Science · Databases

No WHERE clause at all

A member of staff types DELETE FROM tblMembers; and runs it. There is no WHERE clause at all.

What do you think this statement does?
How sure are you?

Exam line: DELETE FROM table with no WHERE clause deletes every record in the table.

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.

6 of 6 still to sort.

Exam line: SELECT retrieves, INSERT adds, UPDATE changes, DELETE removes.

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

1DELETE FROM table WHERE criteria removes the records that the WHERE clause catches.
2AND is evaluated before OR, like multiplication before addition; brackets can make the intention clearer.
3Criteria that are missing or too broad delete more records than intended, and with no WHERE clause every record is deleted.
4SELECT retrieves records, INSERT adds new ones, UPDATE changes existing ones and DELETE removes them.

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?
SQL (structured query language) manages data in relational databases through standardised commands, which must follow specific syntax rules to execute correctly.
Basic syntax of the SQL DELETE statement
DELETE FROM table WHERE criteria
What does the WHERE clause decide in a DELETE?
Which records are deleted: the criteria say which records go.
How do you set more than one criterion in a WHERE clause?
Join the conditions with AND or OR; you do not write WHERE again.
AND and OR in one WHERE clause: which is evaluated first?
AND, just as multiplication takes precedence over addition.
What can brackets do in a WHERE clause?
Group conditions together to make your intention clearer.
What happens if a DELETE has no suitable criteria?
It deletes more records than intended; with no WHERE clause at all, every record is deleted.
Which SQL command retrieves records, and what does SELECT * return?
SELECT retrieves data; SELECT * returns all fields.
Which SQL commands add new records and change existing ones?
INSERT adds new records; UPDATE changes existing records.

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 posted

More AQA GCSE Computer Science topics

See the full AQA Computer Science curriculum →

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.