SQL Filtering with WHERE Clause 3 — Questions and Answers
Question 1: Which query finds products priced 100 or less OR with quantity above 50?
- WHERE price <= 100 OR quantity > 50 (Correct answer)
- WHERE price <= 100 AND quantity > 50
- WHERE price < 100 OR quantity >= 50
- WHERE price = 100 OR quantity = 50
Correct answer: WHERE price <= 100 OR quantity > 50
OR returns rows satisfying at least one of the two conditions exactly as written.
Question 2: What is the result of WHERE quantity NOT IN (1, 2, 3)?
- Rows where quantity is none of 1, 2, or 3 (Correct answer)
- Rows where quantity equals 1, 2, or 3
- Rows where quantity is between 1 and 3
- Rows where quantity is NULL
Correct answer: Rows where quantity is none of 1, 2, or 3
NOT IN excludes rows matching any value in the list.
Question 3: Which condition matches strings containing 'sql' anywhere in the column?
- LIKE '%sql%' (Correct answer)
- LIKE 'sql%'
- LIKE '%sql'
- LIKE '_sql_'
Correct answer: LIKE '%sql%'
Percent signs on both sides match the substring anywhere within the value.
Question 4: How do you select rows where a column does have a value (not null)?
- WHERE column IS NOT NULL (Correct answer)
- WHERE column != NULL
- WHERE column <> NULL
- WHERE column = NOT NULL
Correct answer: WHERE column IS NOT NULL
IS NOT NULL is the correct syntax to test for a present value.
Question 5: Given WHERE a = 1 OR b = 2 AND c = 3, which is evaluated first?
- b = 2 AND c = 3 (Correct answer)
- a = 1 OR b = 2
- All conditions equally
- c = 3 OR a = 1
Correct answer: b = 2 AND c = 3
AND has higher precedence than OR, so the AND pair is evaluated first.
Question 6: Which query filters dates in the year 2025 using a range?
- WHERE order_date BETWEEN '2025-01-01' AND '2025-12-31' (Correct answer)
- WHERE order_date IN '2025'
- WHERE order_date LIKE 2025
- WHERE order_date = 2025
Correct answer: WHERE order_date BETWEEN '2025-01-01' AND '2025-12-31'
BETWEEN with start and end dates filters an inclusive date range.
Question 7: What does the ESCAPE clause do in a LIKE expression?
- Lets you treat wildcard characters as literals (Correct answer)
- Speeds up the LIKE search
- Converts text to uppercase
- Reverses the match logic
Correct answer: Lets you treat wildcard characters as literals
ESCAPE defines a character so wildcards like % or _ can be matched literally.
Which query finds products priced 100 or less OR with quantity above 50?