Challenge - 5 Problems
NULL Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2: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);
Attempts:
2 left
💡 Hint
Look for rows where the manager_id column has no value (NULL).
✗ Incorrect
The query filters rows where manager_id IS NULL, so only employees without a manager are returned: Alice and Charlie.
❓ query_result
intermediate2: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);
Attempts:
2 left
💡 Hint
Look for rows where the manager_id column has a value (not NULL).
✗ Incorrect
The query returns employees who have a manager_id value, which are Bob and Diana.
🧠 Conceptual
advanced2:00remaining
Understanding NULL comparison behavior
Which statement about NULL in SQL is correct?
Attempts:
2 left
💡 Hint
Think about how SQL treats NULL as an unknown value.
✗ Incorrect
In SQL, NULL means unknown, so comparisons with = or <> return UNKNOWN, not TRUE or FALSE. IS NULL and IS NOT NULL are used to check for NULL values.
📝 Syntax
advanced2:00remaining
Identify the common mistake in NULL check
Which option contains a common mistake when checking for NULL values in MySQL?
Attempts:
2 left
💡 Hint
Check which one is incorrect for NULL comparison.
✗ Incorrect
Using = NULL or <> NULL is incorrect in MySQL for NULL checks because they always evaluate to UNKNOWN. IS NULL and IS NOT NULL must be used instead.
❓ optimization
expert3: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?Attempts:
2 left
💡 Hint
Think about correct and efficient NULL checks.
✗ Incorrect
Option B uses the correct and straightforward syntax to check for NULL values. Option B does not work because it always evaluates to UNKNOWN. Option B is logically correct but less clear and may be less optimized. Option B is a trick that returns no rows because NULL <> NULL is UNKNOWN.