The WHERE clause is one of the most important parts of an SQL query in IB Computer Science. While SELECT chooses what data to display, the WHERE clause decides which records are included. Many students understand SELECT but lose marks by misunderstanding how WHERE conditions filter data.
IB examiners expect students to explain how WHERE works, not just include it in queries.
What Is a WHERE Clause?
A WHERE clause is used to:
- Filter records in a table
- Select only records that meet specific conditions
Without a WHERE clause:
- All records in the table are returned
With a WHERE clause:
- Only records that satisfy the condition are included
In IB terms, WHERE controls data selection criteria.
Basic Structure of a WHERE Clause
A WHERE clause follows the FROM clause:
- SELECT field(s)
- FROM table
- WHERE condition
The condition is a logical test that evaluates to true or false for each record.
Only records that evaluate to true are returned.
Using Comparison Operators
WHERE clauses commonly use comparison operators to filter data.
These include:
- Equals
- Not equals
- Greater than
- Less than
- Greater than or equal to
- Less than or equal to
These operators allow:
- Numeric comparisons
- Text matching
- Date filtering
IB students should explain how these operators restrict results, not just list them.
Filtering Text Values
When filtering text:
- Conditions match specific values
- Only exact matches are returned unless otherwise specified
This is often used to:
- Find records for a specific category
- Select users with a given status
Students should be careful to distinguish between field names and values in explanations.
Using Multiple Conditions
WHERE clauses can include multiple conditions.
This allows queries to:
- Narrow results further
- Apply more precise filters
Multiple conditions are combined using logical operators such as:
- AND
- OR
Using AND:
- All conditions must be true
Using OR:
- At least one condition must be true
IB examiners often test understanding of logical combination, not syntax memorisation.
Using WHERE with Numbers
WHERE is often used with numeric data to:
- Filter ranges
- Compare values
- Identify thresholds
Examples include:
- Selecting values above a certain number
- Identifying records below a limit
Students should focus on explaining why a condition selects certain records.
WHERE vs SELECT: A Key Distinction
A common IB mistake is confusing SELECT and WHERE.
- SELECT chooses columns
- WHERE filters rows
Clear explanations that make this distinction score higher marks.
Order of Execution (Conceptual)
Conceptually:
- The database identifies the table
- WHERE filters the records
- SELECT chooses which fields to display
IB students do not need internal DBMS details, but logical sequencing helps explanations.
Common Student Mistakes
Students often:
- Put conditions in SELECT instead of WHERE
- Forget that WHERE filters rows
- Misuse AND and OR logic
- Give vague explanations
Precision matters.
How WHERE Clauses Appear in IB Exams
IB questions may ask students to:
- Write a WHERE clause for a scenario
- Explain what a condition does
- Modify conditions to refine results
- Identify incorrect filtering logic
Clear reasoning earns higher marks than perfect syntax alone.
Final Thoughts
The WHERE clause is what turns SQL from a data display tool into a powerful data filtering system. By applying conditions, SQL can retrieve exactly the records needed from large datasets.
Understanding how WHERE clauses and conditions work allows IB Computer Science students to explain queries clearly, logically, and confidently — exactly what examiners expect.
