Challenge - 5 Problems
Master of WHERE with OR
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Output of WHERE with OR filtering
Given the table Employees with columns
id, name, and department, what rows will this query return?SELECT * FROM Employees WHERE department = 'Sales' OR department = 'HR';
SQL
CREATE TABLE Employees (id INT, name VARCHAR(50), department VARCHAR(50)); INSERT INTO Employees VALUES (1, 'Alice', 'Sales'), (2, 'Bob', 'HR'), (3, 'Charlie', 'IT'), (4, 'Diana', 'Sales');
Attempts:
2 left
💡 Hint
Remember OR means either condition can be true to include the row.
✗ Incorrect
The query selects rows where the department is either 'Sales' or 'HR'. So employees Alice, Bob, and Diana match.
❓ query_result
intermediate2:00remaining
Rows returned with mixed OR conditions
Consider the table Products with columns
product_id, category, and price. What rows will this query return?SELECT * FROM Products WHERE category = 'Books' OR price < 20;
SQL
CREATE TABLE Products (product_id INT, category VARCHAR(50), price DECIMAL); INSERT INTO Products VALUES (1, 'Books', 25), (2, 'Electronics', 15), (3, 'Books', 10), (4, 'Clothing', 30);
Attempts:
2 left
💡 Hint
Rows with category 'Books' or price less than 20 are included.
✗ Incorrect
Rows 1 and 3 have category 'Books'. Row 2 has price less than 20. So rows 1, 2, and 3 are returned.
📝 Syntax
advanced2:00remaining
Identify the syntax error in OR condition
Which option contains a syntax error in the WHERE clause using OR operator?
Attempts:
2 left
💡 Hint
Look for incomplete conditions after OR.
✗ Incorrect
Option B ends with OR but no condition after it, causing syntax error.
❓ optimization
advanced2:00remaining
Optimizing OR conditions in WHERE clause
Which query is more efficient when filtering rows where
category is 'A' or 'B' or 'C'?Attempts:
2 left
💡 Hint
IN clause is often optimized for multiple OR conditions.
✗ Incorrect
Option D uses IN which is clearer and usually optimized by SQL engines compared to multiple ORs.
🧠 Conceptual
expert3:00remaining
Understanding operator precedence with OR and AND
What is the result of this query on table Tasks with columns
Assuming rows:
1: (1, 'Open', 'Low')
2: (2, 'In Progress', 'High')
3: (3, 'In Progress', 'Low')
4: (4, 'Closed', 'High')
id, status, and priority? SELECT * FROM Tasks WHERE status = 'Open' OR status = 'In Progress' AND priority = 'High';
Assuming rows:
1: (1, 'Open', 'Low')
2: (2, 'In Progress', 'High')
3: (3, 'In Progress', 'Low')
4: (4, 'Closed', 'High')
Attempts:
2 left
💡 Hint
AND has higher precedence than OR in SQL.
✗ Incorrect
The condition is evaluated as status = 'Open' OR (status = 'In Progress' AND priority = 'High'). So rows 1 and 2 match.