0
0
MySQLquery~20 mins

IS NULL and IS NOT NULL in MySQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
NULL Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Output of IS NULL filter
Given the table Employees with columns id, name, and manager_id where manager_id can be NULL, what is the output of this query?
SELECT name FROM Employees WHERE manager_id IS NULL;
MySQL
CREATE TABLE Employees (id INT, name VARCHAR(20), manager_id INT);
INSERT INTO Employees VALUES (1, 'Alice', NULL), (2, 'Bob', 1), (3, 'Charlie', NULL), (4, 'Diana', 2);
A[{"name": "Alice"}, {"name": "Charlie"}]
B[{"name": "Alice"}, {"name": "Bob"}, {"name": "Charlie"}, {"name": "Diana"}]
C[]
D[{"name": "Bob"}, {"name": "Diana"}]
Attempts:
2 left
💡 Hint
Look for rows where the manager_id column has no value (NULL).
query_result
intermediate
2:00remaining
Output of IS NOT NULL filter
Using the same Employees table, what is the output of this query?
SELECT name FROM Employees WHERE manager_id IS NOT NULL;
MySQL
CREATE TABLE Employees (id INT, name VARCHAR(20), manager_id INT);
INSERT INTO Employees VALUES (1, 'Alice', NULL), (2, 'Bob', 1), (3, 'Charlie', NULL), (4, 'Diana', 2);
A[{"name": "Alice"}, {"name": "Charlie"}]
B[]
C[{"name": "Alice"}, {"name": "Bob"}, {"name": "Charlie"}, {"name": "Diana"}]
D[{"name": "Bob"}, {"name": "Diana"}]
Attempts:
2 left
💡 Hint
Look for rows where the manager_id column has a value (not NULL).
🧠 Conceptual
advanced
2:00remaining
Understanding NULL comparison behavior
Which statement about NULL in SQL is correct?
ANULL can be compared with any value using = and <> operators safely.
BNULL <> NULL returns FALSE because NULL is not equal to itself.
CNULL comparisons using = or <> always return UNKNOWN, so IS NULL or IS NOT NULL must be used.
DNULL = NULL returns TRUE because both are unknown values.
Attempts:
2 left
💡 Hint
Think about how SQL treats NULL as an unknown value.
📝 Syntax
advanced
2:00remaining
Identify the common mistake in NULL check
Which option contains a common mistake when checking for NULL values in MySQL?
ASELECT * FROM Orders WHERE shipped_date = NULL;
BSELECT * FROM Orders WHERE shipped_date IS NOT NULL;
CSELECT * FROM Orders WHERE shipped_date IS NULL;
DSELECT * FROM Orders WHERE shipped_date <> NULL;
Attempts:
2 left
💡 Hint
Check which one is incorrect for NULL comparison.
optimization
expert
3:00remaining
Optimizing NULL checks in WHERE clause
Consider a large table Products with a nullable column discount_price. Which query is the most efficient to find products without a discount price?
ASELECT * FROM Products WHERE discount_price = NULL;
BSELECT * FROM Products WHERE discount_price IS NULL;
CSELECT * FROM Products WHERE NOT discount_price IS NOT NULL;
DSELECT * FROM Products WHERE discount_price <> discount_price;
Attempts:
2 left
💡 Hint
Think about correct and efficient NULL checks.