0
0
SQLquery~20 mins

WHERE with BETWEEN range in SQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
BETWEEN Mastery
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 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);
ARows with Age 25, 26, 27, 28, 29, 30, 31
BRows with Age 26, 27, 28, 29
CRows with Age 25, 28, and 30
DRows with Age 24, 25, 26, 27, 28, 29, 30
Attempts:
2 left
💡 Hint
BETWEEN includes the boundary values.
🧠 Conceptual
intermediate
2: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?
ASELECT * FROM Orders WHERE OrderDate BETWEEN '2023-01-01' AND '2023-01-31';
BSELECT * FROM Orders WHERE OrderDate > '2023-01-01' AND OrderDate < '2023-01-31';
CSELECT * FROM Orders WHERE OrderDate >= '2023-01-01' AND OrderDate <= '2023-01-31';
DSELECT * FROM Orders WHERE OrderDate > '2023-01-01' AND OrderDate <= '2023-01-31';
Attempts:
2 left
💡 Hint
BETWEEN includes both start and end dates.
📝 Syntax
advanced
2: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;
ASELECT * FROM Products WHERE Price BETWEEN 10 AND 20;
BSELECT * FROM Products WHERE Price BETWEEN 10 AND 20 OR Stock > 0;
CSELECT * FROM Products WHERE Price BETWEEN 10;
DSELECT * FROM Products WHERE Price BETWEEN 10 AND 20 AND Stock > 0;
Attempts:
2 left
💡 Hint
BETWEEN requires two values separated by AND.
optimization
advanced
2: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?
ASELECT * FROM Sales WHERE SaleDate > '2023-01-01' AND SaleDate < '2023-01-31';
BSELECT * FROM Sales WHERE SaleDate >= '2023-01-01' AND SaleDate <= '2023-01-31';
CSELECT * FROM Sales WHERE YEAR(SaleDate) = 2023 AND MONTH(SaleDate) = 1;
DSELECT * FROM Sales WHERE SaleDate BETWEEN '2023-01-01' AND '2023-01-31';
Attempts:
2 left
💡 Hint
Functions on indexed columns can prevent index use.
🔧 Debug
expert
3:00remaining
Why does this BETWEEN query return no rows?
Consider this query:
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?
ABecause the dates are in the wrong format and cause an error.
BBecause the start date is after the end date, BETWEEN returns no rows.
CBecause BETWEEN only works with numeric columns, not dates.
DBecause the query needs to use >= and <= instead of BETWEEN.
Attempts:
2 left
💡 Hint
BETWEEN expects the first value to be less than or equal to the second.