0
0
SQLquery~20 mins

WHERE with comparison operators in SQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Master of WHERE with comparison operators
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Output of a WHERE clause with greater than operator
Given the table Employees with columns id, name, and salary, what rows will this query return?

SELECT * FROM Employees WHERE salary > 50000;
SQL
CREATE TABLE Employees (id INT, name VARCHAR(20), salary INT);
INSERT INTO Employees VALUES (1, 'Alice', 48000), (2, 'Bob', 52000), (3, 'Charlie', 50000), (4, 'Diana', 60000);
ARows with id 2 and 4
BRows with id 1 and 3
CRows with id 3 and 4
DAll rows
Attempts:
2 left
💡 Hint
The > operator means strictly greater than, so salary must be more than 50000.
query_result
intermediate
2:00remaining
Filtering rows with BETWEEN operator
What rows will this query return from the Products table with columns product_id, price if the query is:

SELECT * FROM Products WHERE price BETWEEN 10 AND 20;
SQL
CREATE TABLE Products (product_id INT, price INT);
INSERT INTO Products VALUES (1, 5), (2, 10), (3, 15), (4, 20), (5, 25);
ARows with product_id 2, 3, and 4
BRows with product_id 1, 2, and 3
CRows with product_id 3 and 4 only
DRows with product_id 2 and 5
Attempts:
2 left
💡 Hint
BETWEEN includes the boundary values 10 and 20.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in this WHERE clause
Which option shows the correct syntax for filtering rows where age is less than 30 in the Users table?
ASELECT * FROM Users WHERE age <> 30;
BSELECT * FROM Users WHERE age =< 30;
CSELECT * FROM Users WHERE age << 30;
DSELECT * FROM Users WHERE age < 30;
Attempts:
2 left
💡 Hint
The less than operator is a single character: <
query_result
advanced
2:00remaining
Result of combining multiple comparison operators
Given the Orders table with columns order_id, amount, and status, what rows will this query return?

SELECT * FROM Orders WHERE amount >= 100 AND amount < 200 AND status = 'shipped';
SQL
CREATE TABLE Orders (order_id INT, amount INT, status VARCHAR(10));
INSERT INTO Orders VALUES (1, 150, 'shipped'), (2, 90, 'shipped'), (3, 180, 'pending'), (4, 120, 'shipped'), (5, 200, 'shipped');
ARows with order_id 1, 4, and 5
BRows with order_id 1 and 4
CRows with order_id 2 and 3
DRows with order_id 3 and 5
Attempts:
2 left
💡 Hint
Check all conditions: amount between 100 and 199 inclusive, and status exactly 'shipped'.
🧠 Conceptual
expert
2:30remaining
Understanding NULL behavior with comparison operators
Consider a table Students with columns student_id and score where some score values are NULL. Which statement about the query below is true?

SELECT * FROM Students WHERE score > 70;
SQL
CREATE TABLE Students (student_id INT, score INT);
INSERT INTO Students VALUES (1, 85), (2, NULL), (3, 70), (4, 90);
ARows with student_id 2 and 3 are returned because NULL is ignored.
BAll rows are returned because NULL is treated as zero.
CRows with student_id 1 and 4 are returned; rows with NULL score are excluded.
DNo rows are returned because NULL causes the comparison to fail.
Attempts:
2 left
💡 Hint
In SQL, any comparison with NULL results in unknown, so those rows are filtered out.