What does the OR operator do in a SQL WHERE clause?
The OR operator allows you to filter rows that meet at least one of multiple conditions. If any condition separated by OR is true, the row is included in the result.
Click to reveal answer
beginner
Write a simple SQL query using WHERE with OR to find employees in department 10 or department 20.
SELECT * FROM employees WHERE department_id = 10 OR department_id = 20;
Click to reveal answer
beginner
Can you combine multiple OR conditions in a WHERE clause?
Yes, you can combine many OR conditions. For example: WHERE condition1 OR condition2 OR condition3. The row is included if any condition is true.
Click to reveal answer
intermediate
How does SQL evaluate WHERE conditions with OR and AND together?
SQL evaluates AND before OR unless parentheses change the order. Use parentheses to group conditions clearly, e.g., WHERE (A OR B) AND C.
Click to reveal answer
beginner
What happens if you use OR with conditions that never match any row?
If none of the OR conditions are true for a row, that row is excluded from the result. OR only includes rows where at least one condition is true.
Click to reveal answer
Which SQL query finds rows where column A is 5 or column B is 10?
ASELECT * FROM table WHERE B = 10;
BSELECT * FROM table WHERE A = 5 AND B = 10;
CSELECT * FROM table WHERE A = 5;
DSELECT * FROM table WHERE A = 5 OR B = 10;
✗ Incorrect
The OR operator includes rows where either A = 5 or B = 10 is true.
What does this query return? SELECT * FROM users WHERE age = 20 OR age = 30;
AUsers who are exactly 20 or exactly 30 years old.
BUsers who are between 20 and 30 years old.
CUsers who are not 20 or 30 years old.
DUsers who are both 20 and 30 years old.
✗ Incorrect
OR checks if age is 20 or age is 30, so it returns users with either age.
How does SQL treat this condition? WHERE A = 1 OR B = 2 AND C = 3
AIt treats AND before OR, so it's A=1 OR (B=2 AND C=3).
BIt treats OR before AND, so it's (A=1 OR B=2) AND C=3.
CIt treats all conditions equally and randomly.
DIt causes a syntax error.
✗ Incorrect
AND has higher precedence than OR, so it evaluates B=2 AND C=3 first.
Which is true about the OR operator in SQL WHERE clause?
AIt returns rows where all conditions are true.
BIt returns rows where at least one condition is true.
CIt returns rows where no conditions are true.
DIt returns rows only if conditions are false.
✗ Incorrect
OR includes rows if any condition separated by OR is true.
What is the result of this query? SELECT * FROM products WHERE price < 10 OR price > 100;
AProducts priced exactly 10 or 100.
BProducts priced between 10 and 100.
CProducts priced less than 10 or greater than 100.
DNo products will be returned.
✗ Incorrect
OR includes products with price less than 10 or greater than 100.
Explain how the OR operator works in a SQL WHERE clause and give a simple example.
Think about choosing between two or more options.
You got /3 concepts.
Describe how SQL evaluates WHERE conditions when both AND and OR operators are used together.
Remember the order of operations like in math.
You got /3 concepts.
Practice
(1/5)
1. What does the SQL WHERE clause with the OR operator do?
easy
A. It deletes rows that meet any condition.
B. It selects rows that meet at least one of the conditions.
C. It selects rows that meet all conditions simultaneously.
D. It updates rows that meet none of the conditions.
Solution
Step 1: Understand the WHERE clause
The WHERE clause filters rows based on conditions.
Step 2: Understand the OR operator
OR means if any condition is true, the row is selected.
Final Answer:
It selects rows that meet at least one of the conditions. -> Option B
Quick Check:
WHERE with OR = any condition true [OK]
Hint: OR means any condition true selects the row [OK]
Common Mistakes:
Thinking OR requires all conditions true
Confusing OR with AND
Assuming OR deletes or updates rows
2. Which of the following SQL queries correctly uses the WHERE clause with the OR operator to find employees in department 10 or 20?
easy
A. SELECT * FROM employees WHERE department_id = 10 AND 20;
B. SELECT * FROM employees WHERE department_id = (10 OR 20);
C. SELECT * FROM employees WHERE department_id = 10 OR department_id = 20;
D. SELECT * FROM employees WHERE department_id IN 10 OR 20;
Solution
Step 1: Check correct OR syntax
OR must connect full conditions: column = value OR column = value.
Step 2: Analyze each option
A uses AND incorrectly; C uses invalid syntax; D misuses IN without parentheses.
Final Answer:
SELECT * FROM employees WHERE department_id = 10 OR department_id = 20; -> Option C
Quick Check:
Correct OR syntax = SELECT * FROM employees WHERE department_id = 10 OR department_id = 20; [OK]
Hint: Use OR between full conditions, not partial expressions [OK]
Common Mistakes:
Using AND instead of OR
Writing OR inside parentheses incorrectly
Misusing IN without parentheses
3. Given the table products with columns id, name, and category, what rows will this query return?
SELECT * FROM products WHERE category = 'Books' OR category = 'Toys';
medium
A. Products in either 'Books' or 'Toys' categories.
B. Only products in both 'Books' and 'Toys' categories.
C. All products except those in 'Books' or 'Toys'.
D. No products because OR is invalid here.
Solution
Step 1: Understand the OR condition
The query selects rows where category is 'Books' or 'Toys'.
Step 2: Determine matching rows
Rows with category 'Books' or 'Toys' will be included, others excluded.
Final Answer:
Products in either 'Books' or 'Toys' categories. -> Option A
Quick Check:
OR selects rows matching any condition [OK]
Hint: OR includes rows matching any listed condition [OK]
Common Mistakes:
Thinking OR means both conditions must be true
Assuming OR excludes matching rows
Believing OR causes syntax error
4. Identify the error in this SQL query:
SELECT * FROM orders WHERE status = 'Pending' OR;
medium
A. Missing condition after OR operator.
B. Incorrect use of WHERE clause.
C. OR operator should be AND.
D. No error, query is valid.
Solution
Step 1: Analyze the WHERE clause
The WHERE clause ends with OR but no condition follows it.
Step 2: Understand OR syntax
OR must connect two conditions; missing second condition causes syntax error.
Final Answer:
Missing condition after OR operator. -> Option A
Quick Check:
OR needs two conditions [OK]
Hint: OR must connect two conditions; don't leave it hanging [OK]
Common Mistakes:
Leaving OR at end without condition
Confusing OR with AND syntax
Ignoring syntax errors in WHERE clause
5. You have a table students with columns id, grade, and city. Write a query to select students who have grade 'A' or live in 'New York' or 'Los Angeles'. Which query is correct?
hard
A. SELECT * FROM students WHERE grade = 'A' OR city = 'New York' OR 'Los Angeles';
B. SELECT * FROM students WHERE grade = 'A' AND city = 'New York' OR 'Los Angeles';
C. SELECT * FROM students WHERE grade = 'A' OR city = 'New York' AND city = 'Los Angeles';
D. SELECT * FROM students WHERE grade = 'A' OR city IN ('New York', 'Los Angeles');
Solution
Step 1: Understand the conditions
Select students with grade 'A' OR city 'New York' OR city 'Los Angeles'.
Step 2: Analyze each query
A has syntax error (missing column in last condition); B has syntax error and wrong logic; C has incorrect logic due to AND; D is correct and concise using IN.
Final Answer:
SELECT * FROM students WHERE grade = 'A' OR city IN ('New York', 'Los Angeles'); -> Option D
Quick Check:
Use OR with IN for multiple values [OK]
Hint: Use OR with IN for multiple city values [OK]
Common Mistakes:
Using AND between city conditions
Omitting column name after OR
Syntax errors with OR and IN
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.