Learning Objectives
  • Use AND and OR in WHERE conditions.
  • Explain the difference between both conditions and at least one condition.
  • Trace compound conditions record by record.
  • Use brackets where they clarify the intended logic.
Key Terms
AND
A logical operator that is true only when both conditions are true.
OR
A logical operator that is true when at least one condition is true.
Compound condition
A condition formed from two or more simpler conditions.
Truth value
TRUE or FALSE result of a condition.
Precedence
The order in which parts of an expression are evaluated.
Brackets
Symbols used to make grouping explicit.
Summary diagram
Summary Of The Main Ideas In This Lesson
Using AND

AND requires every connected condition to be true. It narrows a query because a record must satisfy more than one requirement.

For example, WHERE YearGroup = 10 AND AverageMark >= 70 returns only records that are both in YearGroup 10 and have an AverageMark of at least 70. A record satisfying only one part is excluded.

Think of AND as the word both. This translation helps prevent selecting too many records.

Using OR

OR requires at least one connected condition to be true. It broadens a query because records can qualify in different ways.

WHERE Category = “A” OR Category = “B” returns records in either permitted category, including a record that meets both conditions if that were possible.

Think of OR as either or both, unless the question explicitly describes an exclusive choice. Topic 9 uses the standard inclusive OR.

AND Example

The query evaluates YearGroup = 10 and AverageMark >= 70 for every record. Only a record with TRUE for both is returned.

The output shows StudentName and AverageMark because those fields are selected. YearGroup is used for filtering but need not be displayed.

SELECT StudentName, AverageMark
FROM Students
WHERE YearGroup = 10 AND AverageMark >= 70;
OR Example

A product is returned if its category is A, if it is not in stock, or if both are true.

Do not require both conditions when the operator is OR.

SELECT ProductID, ProductName
FROM Products
WHERE Category = "A" OR InStock = FALSE;
Truth Summary
Condition A Condition B A AND B A OR B
FALSE FALSE FALSE FALSE
FALSE TRUE FALSE TRUE
TRUE FALSE FALSE TRUE
TRUE TRUE TRUE TRUE
Tracing Compound Conditions
Student YearGroup = 10 AverageMark >= 70 AND Result OR Result
Amina TRUE TRUE TRUE TRUE
Bilal TRUE FALSE FALSE TRUE
Chen FALSE TRUE FALSE TRUE
Dina FALSE FALSE FALSE FALSE
Using More Than Two Conditions

A query can connect several conditions using AND or OR. Work from the grouping shown. Brackets are useful when both operators appear because they make the intended logic explicit.

For example, WHERE InStock = TRUE AND (Category = “A” OR Category = “B”) means the product must be in stock and must belong to either category A or B.

Avoid introducing complex SQL features outside the syllabus. The assessed skill is understanding and completing conditions with AND and OR.

Translating Natural Language

Words such as and, both and all normally indicate AND. Words such as either, any of and at least one normally indicate OR.

Read carefully when the word or occurs in ordinary language. The required logic should follow the stated acceptance rule, not simply the presence of the word.

Worked Examples
Both Conditions

Question: Display names of employees who are in Department A and have CompletedTraining = TRUE.

  1. Both requirements must be satisfied.
  2. Use AND between the two conditions.
  3. Select only the requested Name field.

Answer: SELECT Name FROM Employees WHERE Department = “A” AND CompletedTraining = TRUE;

Either Category

Question: Display ProductID for category X or category Y.

  1. A product can match either category.
  2. Use OR between two equality tests.

Answer: SELECT ProductID FROM Products WHERE Category = “X” OR Category = “Y”;

Examination Guidance
  • Translate both as AND and either as OR.
  • Use the truth table when tracing a compound condition.
  • Evaluate conditions for each record separately.
  • Use brackets to make mixed AND/OR grouping clear.
  • Display only fields named by SELECT.
Common Mistakes
  • Using AND when either condition is enough.
  • Using OR when both conditions are required.
  • Stopping after the first false condition without considering OR.
  • Ignoring brackets in a mixed expression.
  • Assuming OR means exactly one condition must be true.
Knowledge Check

1. When is A AND B true?

Answer: Only when both A and B are true.

2. When is A OR B true?

Answer: When at least one is true.

3. Which operator normally narrows a query?

Answer: AND.

4. Which operator normally broadens a query?

Answer: OR.

5. Why use brackets?

Answer: To make the grouping of conditions explicit.