What does the SQL BETWEEN operator do in a WHERE clause?
The BETWEEN operator filters the results to include only rows where a column's value falls within a specified range, including the boundary values.
Click to reveal answer
beginner
Write a SQL query to select all products with prices between 10 and 20 inclusive.
SELECT * FROM products WHERE price BETWEEN 10 AND 20;
Click to reveal answer
beginner
Is the BETWEEN operator inclusive or exclusive of the range boundaries?
The BETWEEN operator is inclusive, meaning it includes both the start and end values of the range.
Click to reveal answer
intermediate
Can BETWEEN be used with dates in SQL?
Yes, BETWEEN works with dates to filter rows where a date column falls within a specified date range.
Click to reveal answer
intermediate
What is the equivalent of WHERE column BETWEEN 5 AND 10 using comparison operators?
It is equivalent to WHERE column >= 5 AND column <= 10.
Click to reveal answer
Which of the following SQL queries correctly selects rows where age is between 18 and 30 inclusive?
ASELECT * FROM users WHERE age > 18 AND age < 30;
BSELECT * FROM users WHERE age = 18 AND age = 30;
CSELECT * FROM users WHERE age >= 18 OR age <= 30;
DSELECT * FROM users WHERE age BETWEEN 18 AND 30;
✗ Incorrect
Option D uses BETWEEN which includes both 18 and 30. Option A excludes 18 and 30. Option C uses OR which is incorrect. Option B is impossible because age cannot be both 18 and 30.
What will the query SELECT * FROM orders WHERE order_date BETWEEN '2024-01-01' AND '2024-01-31'; return?
AOrders placed from January 1 to January 31, 2024, inclusive.
BOrders placed only on January 1 and January 31, 2024.
COrders placed before January 1, 2024.
DOrders placed after January 31, 2024.
✗ Incorrect
The BETWEEN operator includes all dates from January 1 to January 31, 2024, inclusive.
Which of these is NOT true about the BETWEEN operator?
AIt includes the boundary values.
BIt can be used with numbers, dates, and text.
CIt is case-sensitive when used with text.
DIt can replace multiple comparison operators.
✗ Incorrect
BETWEEN itself is not case-sensitive; case sensitivity depends on the database collation settings, not the operator.
How would you rewrite WHERE score BETWEEN 50 AND 100 using only comparison operators?
AWHERE score >= 50 AND score <= 100
BWHERE score = 50 OR score = 100
CWHERE score > 50 OR score < 100
DWHERE score > 50 AND score < 100
✗ Incorrect
The BETWEEN operator is inclusive, so it is equivalent to using >= and <=.
If you want to find records where a value is NOT between 10 and 20, which SQL clause would you use?
AWHERE value BETWEEN 10 AND 20
BWHERE value NOT BETWEEN 10 AND 20
CWHERE value >= 10 AND value <= 20
DWHERE value = 10 OR value = 20
✗ Incorrect
NOT BETWEEN excludes values within the range, including boundaries.
Explain how the BETWEEN operator works in a SQL WHERE clause and give an example.
Think about filtering rows within a range of values.
You got /3 concepts.
Describe how you can use BETWEEN with dates and why it might be useful.
Consider filtering records within a specific time period.
You got /3 concepts.
Practice
(1/5)
1. What does the SQL clause WHERE column BETWEEN 10 AND 20 do?
easy
A. Selects rows where the column value is greater than 10 but less than 20, excluding 10 and 20
B. Selects rows where the column value is between 10 and 20, including 10 and 20
C. Selects rows where the column value is exactly 10 or exactly 20 only
D. Selects rows where the column value is less than 10 or greater than 20
Solution
Step 1: Understand BETWEEN clause behavior
The BETWEEN clause includes both the start and end values in the range.
Step 2: Apply to the given range 10 to 20
This means values equal to 10, 20, or any number between them are selected.
Final Answer:
Selects rows where the column value is between 10 and 20, including 10 and 20 -> Option B
Quick Check:
BETWEEN includes boundaries = B [OK]
Hint: BETWEEN includes both start and end values [OK]
Common Mistakes:
Thinking BETWEEN excludes boundary values
Confusing BETWEEN with > and < operators
Assuming BETWEEN works only with numbers
2. Which of the following is the correct syntax to select rows where age is between 18 and 30?
easy
A. SELECT * FROM users WHERE age BETWEEN (18 AND 30);
B. SELECT * FROM users WHERE age BETWEEN 18 TO 30;
C. SELECT * FROM users WHERE age BETWEEN 18, 30;
D. SELECT * FROM users WHERE age BETWEEN 18 AND 30;
Solution
Step 1: Recall correct BETWEEN syntax
The correct syntax uses BETWEEN start AND end without commas or parentheses.
Step 2: Check each option
SELECT * FROM users WHERE age BETWEEN 18 AND 30; uses correct syntax: BETWEEN 18 AND 30. Others have syntax errors.
Final Answer:
SELECT * FROM users WHERE age BETWEEN 18 AND 30; -> Option D
Quick Check:
BETWEEN ... AND ... syntax = D [OK]
Hint: BETWEEN always uses AND, never TO or commas [OK]
Common Mistakes:
Using TO instead of AND
Adding commas between values
Using parentheses around BETWEEN clause
3. Given the table products with a column price, what rows will this query return?
SELECT * FROM products WHERE price BETWEEN 50 AND 100;
Assume the prices in the table are: 45, 50, 75, 100, 120.
medium
A. Rows with prices 50, 75, and 100
B. Rows with prices 45, 50, 75, 100, and 120
C. Rows with prices 75 and 100 only
D. Rows with prices 50 and 100 only
Solution
Step 1: Identify the range in BETWEEN clause
The query filters prices between 50 and 100, including both 50 and 100.
Step 2: Check which prices fall in this range
Prices 50, 75, and 100 are within the range; 45 and 120 are outside.
Final Answer:
Rows with prices 50, 75, and 100 -> Option A
Quick Check:
BETWEEN includes boundaries, so 50 and 100 included = A [OK]
Hint: BETWEEN includes start and end values in results [OK]
Common Mistakes:
Excluding boundary values 50 and 100
Including values outside the range like 45 or 120
Confusing BETWEEN with > and < operators
4. Identify the error in this SQL query:
SELECT * FROM orders WHERE order_date BETWEEN '2023-01-01' TO '2023-01-31';
medium
A. Using TO instead of AND in BETWEEN clause
B. Dates should not be in quotes
C. BETWEEN cannot be used with dates
D. Missing semicolon at the end
Solution
Step 1: Check BETWEEN syntax
BETWEEN requires AND between the two values, not TO.
Step 2: Validate other parts
Dates in quotes are correct, BETWEEN works with dates, and semicolon is optional in many systems.
Final Answer:
Using TO instead of AND in BETWEEN clause -> Option A
Quick Check:
BETWEEN uses AND, not TO = A [OK]
Hint: BETWEEN always uses AND, never TO [OK]
Common Mistakes:
Replacing AND with TO in BETWEEN
Thinking dates can't be quoted
Assuming semicolon is mandatory
5. You want to select employees hired between January 1, 2020, and December 31, 2022, inclusive. Which query correctly uses BETWEEN and also excludes employees hired on weekends?
SELECT * FROM employees WHERE hire_date BETWEEN '2020-01-01' AND '2022-12-31' AND EXTRACT(DOW FROM hire_date) NOT IN (0,6);
What does this query do?
hard
A. Selects employees hired between the dates including weekends
B. Selects employees hired only on weekends between the dates
C. Selects employees hired between the dates excluding weekends
D. Syntax error due to EXTRACT usage
Solution
Step 1: Understand BETWEEN usage
The query selects employees hired from 2020-01-01 to 2022-12-31 inclusive.
Step 2: Analyze EXTRACT(DOW FROM hire_date) condition
EXTRACT(DOW) returns day of week (0=Sunday, 6=Saturday). NOT IN (0,6) excludes weekends.
Step 3: Combine conditions
Only employees hired on weekdays within the date range are selected.
Final Answer:
Selects employees hired between the dates excluding weekends -> Option C
Quick Check:
BETWEEN + weekday filter = C [OK]
Hint: Use BETWEEN for range and filter weekdays with EXTRACT [OK]
Common Mistakes:
Assuming BETWEEN excludes boundaries
Confusing day numbers for weekend days
Thinking EXTRACT causes syntax error
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.