Mixing AND and OR with brackets in a WHERE clause
Brackets make SQL work out the OR first, then the AND. A record must meet C and also A or B. Moving the brackets, as in A OR (B AND C), can return different records.
Understanding Mixing AND and OR with brackets in a WHERE clause in IGCSE Computer Science Paper 2
What it does: The OR on yearLevel is worked out first. Records then still need points above 100, so the AND condition applies to both year levels. With AND, both sides must be true. (A OR B) can be true, but if C is false the record is not returned. Using the same field twice with OR needs brackets before AND price < 20. The correct version returns only USB Drive and Water Bottle. The wrong one also returns every Tech product, such as Headphones. The brackets make the AND work first. A Red house student qualifies on their own, but a Blue house student must also be in Year 7.
Common mistakes: The opening bracket is missing, so the closing bracket on line 3 has no partner. It should be WHERE (house = 'Red'. The brackets make the OR work first, then the AND. The semicolon ends the statement too early, so the AND (...) part is never read. The semicolon belongs only at the very end of the whole WHERE clause.
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 525–538) and word search (Modules 500–538).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
WHERE (A OR B) AND CFill in the Blanks
Spot the Error
Student with a class code? Join your class →