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
