Bird
Raised Fist0
SQLquery~10 mins

WHERE with OR operator in SQL - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to select all rows where the city is either 'New York' or 'Los Angeles'.

SQL
SELECT * FROM customers WHERE city [1] 'New York' OR city = 'Los Angeles';
Drag options to blanks, or click blank then click option'
A!=
B=
C<>
DLIKE
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' or '<>' which check for inequality.
Using 'LIKE' without wildcards.
2fill in blank
medium

Complete the code to select products where the category is 'Books' or the price is less than 20.

SQL
SELECT * FROM products WHERE category = 'Books' OR price [1] 20;
Drag options to blanks, or click blank then click option'
A>
B=
C<
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' which selects prices greater than 20.
Using '=' which selects prices exactly 20.
3fill in blank
hard

Fix the error in the query to select employees who work in 'HR' or have a salary greater than 50000.

SQL
SELECT * FROM employees WHERE department = 'HR' [1] salary > 50000;
Drag options to blanks, or click blank then click option'
AOR
BAND
CNOT
DXOR
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'AND' which restricts results to both conditions.
Using 'NOT' or 'XOR' which are not appropriate here.
4fill in blank
hard

Fill both blanks to select orders where the status is 'Pending' or the total is greater than 100.

SQL
SELECT * FROM orders WHERE status [1] 'Pending' [2] total > 100;
Drag options to blanks, or click blank then click option'
A=
B<
COR
DAND
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'AND' instead of 'OR' which restricts results.
Using '<' in the first blank which is incorrect for string comparison.
5fill in blank
hard

Fill all three blanks to select customers who live in 'Chicago' or 'Houston' and have made more than 5 orders.

SQL
SELECT * FROM customers WHERE (city = [1] [2] city = [3]) AND orders_count > 5;
Drag options to blanks, or click blank then click option'
A'Chicago'
B'Houston'
COR
DAND
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'AND' instead of 'OR' between city conditions.
Not using quotes around city names.

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

  1. Step 1: Understand the WHERE clause

    The WHERE clause filters rows based on conditions.
  2. Step 2: Understand the OR operator

    OR means if any condition is true, the row is selected.
  3. Final Answer:

    It selects rows that meet at least one of the conditions. -> Option B
  4. 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

  1. Step 1: Check correct OR syntax

    OR must connect full conditions: column = value OR column = value.
  2. Step 2: Analyze each option

    A uses AND incorrectly; C uses invalid syntax; D misuses IN without parentheses.
  3. Final Answer:

    SELECT * FROM employees WHERE department_id = 10 OR department_id = 20; -> Option C
  4. 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

  1. Step 1: Understand the OR condition

    The query selects rows where category is 'Books' or 'Toys'.
  2. Step 2: Determine matching rows

    Rows with category 'Books' or 'Toys' will be included, others excluded.
  3. Final Answer:

    Products in either 'Books' or 'Toys' categories. -> Option A
  4. 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

  1. Step 1: Analyze the WHERE clause

    The WHERE clause ends with OR but no condition follows it.
  2. Step 2: Understand OR syntax

    OR must connect two conditions; missing second condition causes syntax error.
  3. Final Answer:

    Missing condition after OR operator. -> Option A
  4. 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

  1. Step 1: Understand the conditions

    Select students with grade 'A' OR city 'New York' OR city 'Los Angeles'.
  2. 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.
  3. Final Answer:

    SELECT * FROM students WHERE grade = 'A' OR city IN ('New York', 'Los Angeles'); -> Option D
  4. 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 unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard