0
0
MySQLquery~20 mins

Comparison operators in MySQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Comparison Operators Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Output of comparison with NULL using = operator
Consider the following SQL query:

SELECT * FROM employees WHERE manager_id = NULL;

What will be the result of this query?
MySQL
SELECT * FROM employees WHERE manager_id = NULL;
AReturns no rows
BReturns all rows where manager_id is NULL
CReturns all rows regardless of manager_id
DRaises a syntax error
Attempts:
2 left
💡 Hint
Remember how NULL behaves in comparisons in SQL.
query_result
intermediate
2:00remaining
Result of BETWEEN operator with boundary values
Given a table 'products' with a column 'price', what rows will this query return?

SELECT * FROM products WHERE price BETWEEN 10 AND 20;

Specifically, will it include products priced exactly 10 or 20?
MySQL
SELECT * FROM products WHERE price BETWEEN 10 AND 20;
AIncludes products priced between 10 and 20 but excludes 10
BExcludes products priced exactly 10 and 20
CIncludes products priced exactly 10 and 20
DIncludes products priced between 10 and 20 but excludes 20
Attempts:
2 left
💡 Hint
BETWEEN includes the boundary values in SQL.
📝 Syntax
advanced
2:00remaining
Identify the invalid comparison operator usage
Which of the following SQL WHERE clauses will cause a syntax error?
AWHERE name =! 'John'
BWHERE salary != 50000
CWHERE age <> 30
DWHERE score >= 75
Attempts:
2 left
💡 Hint
Check the correct syntax for 'not equal' in SQL.
optimization
advanced
2:00remaining
Optimizing a query with multiple OR conditions
You have a table 'orders' with a column 'status'. Which query is more efficient to find orders with status 'pending', 'processing', or 'shipped'?
ASELECT * FROM orders WHERE status = 'pending' OR status = 'processing' OR status = 'shipped';
BSELECT * FROM orders WHERE status BETWEEN 'pending' AND 'shipped';
CSELECT * FROM orders WHERE status LIKE 'pending' OR status LIKE 'processing' OR status LIKE 'shipped';
DSELECT * FROM orders WHERE status IN ('pending', 'processing', 'shipped');
Attempts:
2 left
💡 Hint
Consider readability and how the database engine optimizes IN vs multiple ORs.
🧠 Conceptual
expert
2:00remaining
Understanding three-valued logic in SQL comparisons
In SQL, what is the result of the expression 5 = NULL and why?
ATRUE, because 5 equals NULL
BUNKNOWN, because NULL represents an unknown value
CFALSE, because 5 does not equal NULL
DSyntax error, because NULL cannot be compared
Attempts:
2 left
💡 Hint
Think about how SQL treats NULL in logical expressions.