Challenge - 5 Problems
BETWEEN Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Output of BETWEEN with inclusive range
Given the table Employees with a column
Age, what rows will be returned by this query?SELECT * FROM Employees WHERE Age BETWEEN 25 AND 30;
SQL
CREATE TABLE Employees (ID INT, Name VARCHAR(20), Age INT); INSERT INTO Employees VALUES (1, 'Alice', 24), (2, 'Bob', 25), (3, 'Carol', 28), (4, 'Dave', 30), (5, 'Eve', 31);
Attempts:
2 left
💡 Hint
BETWEEN includes the boundary values.
✗ Incorrect
The BETWEEN operator includes both the start and end values, so ages 25, 26, 27, 28, 29, and 30 are included. Ages 24 and 31 are outside the range.
🧠 Conceptual
intermediate2:00remaining
Understanding BETWEEN with dates
Which of the following queries correctly selects records from
Orders where OrderDate is between January 1, 2023 and January 31, 2023 inclusive?Attempts:
2 left
💡 Hint
BETWEEN includes both start and end dates.
✗ Incorrect
BETWEEN is inclusive, so option A correctly includes orders on January 1 and January 31. Option A is equivalent but option A uses BETWEEN syntax.
📝 Syntax
advanced2:00remaining
Identify the syntax error in BETWEEN usage
Which option contains a syntax error in the use of BETWEEN in this query?
SELECT * FROM Products WHERE Price BETWEEN 10 AND;
Attempts:
2 left
💡 Hint
BETWEEN requires two values separated by AND.
✗ Incorrect
Option C is missing the second value after AND, causing a syntax error.
❓ optimization
advanced2:00remaining
Optimizing BETWEEN with indexes
Given a large table
Sales with an index on SaleDate, which query will best use the index to filter sales between two dates?Attempts:
2 left
💡 Hint
Functions on indexed columns can prevent index use.
✗ Incorrect
Option D uses functions on SaleDate which disables index usage. Options A, B, and D use the index well. Option D excludes boundary dates.
🔧 Debug
expert3:00remaining
Why does this BETWEEN query return no rows?
Consider this query:
Why does it return no rows even though the table has events in April and May 2023?
SELECT * FROM Events WHERE EventDate BETWEEN '2023-05-01' AND '2023-04-30';
Why does it return no rows even though the table has events in April and May 2023?
Attempts:
2 left
💡 Hint
BETWEEN expects the first value to be less than or equal to the second.
✗ Incorrect
BETWEEN requires the first value to be less than or equal to the second. Here, '2023-05-01' is after '2023-04-30', so no rows match.