Challenge - 5 Problems
BETWEEN Range Master
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 Products with a column
price, what rows will this query return?SELECT * FROM Products WHERE price BETWEEN 10 AND 20;MySQL
CREATE TABLE Products (id INT, name VARCHAR(20), price INT); INSERT INTO Products VALUES (1, 'Pen', 5), (2, 'Notebook', 15), (3, 'Bag', 20), (4, 'Pencil', 25);
Attempts:
2 left
💡 Hint
BETWEEN includes both the start and end values.
✗ Incorrect
BETWEEN 10 AND 20 includes prices 10, 20 and all values in between. So products with price 15 and 20 match.
❓ query_result
intermediate2:00remaining
BETWEEN with dates
What rows will this query return from the Orders table?
SELECT * FROM Orders WHERE order_date BETWEEN '2023-01-01' AND '2023-01-31';MySQL
CREATE TABLE Orders (id INT, order_date DATE); INSERT INTO Orders VALUES (1, '2022-12-31'), (2, '2023-01-01'), (3, '2023-01-15'), (4, '2023-02-01');
Attempts:
2 left
💡 Hint
BETWEEN includes the boundary dates.
✗ Incorrect
BETWEEN '2023-01-01' AND '2023-01-31' includes all dates from January 1 to January 31, inclusive.
📝 Syntax
advanced2:00remaining
Identify the syntax error in BETWEEN usage
Which option contains a syntax error in using BETWEEN in MySQL?
Attempts:
2 left
💡 Hint
BETWEEN requires AND between two values, not a comma.
✗ Incorrect
Option A uses a comma instead of AND, which is invalid syntax for BETWEEN.
❓ optimization
advanced2:00remaining
Optimizing range queries with BETWEEN
Which query is more efficient for filtering ages between 18 and 30 in a large table Users?
Attempts:
2 left
💡 Hint
BETWEEN is optimized for range filtering in SQL engines.
✗ Incorrect
BETWEEN is concise and often optimized internally for range checks, making it efficient and readable.
🧠 Conceptual
expert2:00remaining
Understanding BETWEEN with NULL values
What will be the result of this query?
Assume the table Scores has some rows with numeric
SELECT * FROM Scores WHERE score BETWEEN 50 AND NULL;Assume the table Scores has some rows with numeric
score values.Attempts:
2 left
💡 Hint
Any comparison with NULL results in unknown, so no rows match.
✗ Incorrect
BETWEEN with NULL as an endpoint results in no matches because comparisons with NULL are unknown in SQL.