SQL Filtering with WHERE Clause 2 — Questions and Answers
Question 1: Which operator checks whether a column value falls within an inclusive range of two values?
- BETWEEN (Correct answer)
- IN
- LIKE
- EXISTS
Correct answer: BETWEEN
BETWEEN tests an inclusive range, so BETWEEN 10 AND 20 includes both 10 and 20.
Question 2: What does WHERE salary IN (3000, 4000, 5000) do?
- Returns rows where salary matches any value in the list (Correct answer)
- Returns rows where salary equals all three values
- Returns rows where salary is between 3000 and 5000
- Returns rows where salary is none of the listed values
Correct answer: Returns rows where salary matches any value in the list
IN returns rows where the column matches any one of the listed values.
Question 3: Which clause correctly filters for names starting with the letter 'A'?
- WHERE name LIKE 'A%' (Correct answer)
- WHERE name LIKE '%A'
- WHERE name = 'A%'
- WHERE name LIKE '_A'
Correct answer: WHERE name LIKE 'A%'
The % wildcard after A matches any sequence of characters following A.
Question 4: How do you select rows where the email column has no value?
- WHERE email IS NULL (Correct answer)
- WHERE email = NULL
- WHERE email = ''
- WHERE email != NULL
Correct answer: WHERE email IS NULL
NULL comparisons require IS NULL because = NULL never evaluates true.
Question 5: In WHERE age > 18 AND city = 'NYC', which rows are returned?
- Only rows where both conditions are true (Correct answer)
- Rows where either condition is true
- Rows where neither condition is true
- All rows regardless of conditions
Correct answer: Only rows where both conditions are true
AND requires both conditions to be true for a row to be included.
Question 6: Which wildcard in LIKE matches exactly one single character?
- Underscore (_) (Correct answer)
- Percent (%)
- Asterisk (*)
- Question mark (?)
Correct answer: Underscore (_)
In standard SQL LIKE, the underscore matches exactly one character.
Question 7: What does WHERE NOT (status = 'active') return?
- Rows where status is not 'active' (Correct answer)
- Rows where status is 'active'
- Only rows where status is NULL
- All rows in the table
Correct answer: Rows where status is not 'active'
NOT negates the condition, returning rows where status is not 'active'.
Which operator checks whether a column value falls within an inclusive range of two values?