0
0
MySQLquery~20 mins

BETWEEN range filtering in MySQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
BETWEEN Range Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2: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);
ARows with id 2 only
BRows with id 1, 2, and 3
CRows with id 2 and 3
DRows with id 3 and 4
Attempts:
2 left
💡 Hint
BETWEEN includes both the start and end values.
query_result
intermediate
2: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');
ARows with id 2 and 3
BRows with id 1, 2, and 3
CRows with id 3 and 4
DRows with id 2, 3, and 4
Attempts:
2 left
💡 Hint
BETWEEN includes the boundary dates.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in BETWEEN usage
Which option contains a syntax error in using BETWEEN in MySQL?
ASELECT * FROM Employees WHERE salary BETWEEN 3000, 5000;
BSELECT * FROM Employees WHERE salary NOT BETWEEN 3000 AND 5000;
CSELECT * FROM Employees WHERE salary BETWEEN 3000 AND 5000 ORDER BY salary;
DSELECT * FROM Employees WHERE salary BETWEEN 3000 AND 5000;
Attempts:
2 left
💡 Hint
BETWEEN requires AND between two values, not a comma.
optimization
advanced
2:00remaining
Optimizing range queries with BETWEEN
Which query is more efficient for filtering ages between 18 and 30 in a large table Users?
ASELECT * FROM Users WHERE age >= 18 AND age <= 30;
BSELECT * FROM Users WHERE age IN (18,19,20,21,22,23,24,25,26,27,28,29,30);
CSELECT * FROM Users WHERE age > 18 AND age < 30;
DSELECT * FROM Users WHERE age BETWEEN 18 AND 30;
Attempts:
2 left
💡 Hint
BETWEEN is optimized for range filtering in SQL engines.
🧠 Conceptual
expert
2:00remaining
Understanding BETWEEN with NULL values
What will be the result of this query?

SELECT * FROM Scores WHERE score BETWEEN 50 AND NULL;

Assume the table Scores has some rows with numeric score values.
AReturns all rows where score is 50 or more
BReturns no rows
CReturns all rows where score is NULL
DRaises a syntax error
Attempts:
2 left
💡 Hint
Any comparison with NULL results in unknown, so no rows match.