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 NULL comparison in WHERE clause
Consider a table Employees with a column
ManagerID that can be NULL. What rows will this query return?SELECT * FROM Employees WHERE ManagerID = NULL;
SQL
SELECT * FROM Employees WHERE ManagerID = NULL;
Attempts:
2 left
💡 Hint
Remember that NULL means unknown, so comparisons with NULL don't behave like normal values.
✗ Incorrect
In SQL, comparing any value to NULL using = returns unknown, which is treated as false in WHERE clauses. To check for NULL, use IS NULL.
❓ query_result
intermediate2:00remaining
Effect of IS NULL vs = NULL in filtering
Given a table Orders with a column
ShippedDate that can be NULL, which query returns all orders that have not been shipped?1) SELECT * FROM Orders WHERE ShippedDate = NULL;
2) SELECT * FROM Orders WHERE ShippedDate IS NULL;
SQL
SELECT * FROM Orders WHERE ShippedDate IS NULL;
Attempts:
2 left
💡 Hint
Think about how SQL treats NULL in equality comparisons versus IS NULL.
✗ Incorrect
The = NULL comparison always returns unknown, so query 1 returns no rows. Query 2 uses IS NULL which correctly filters rows with NULL values.
🧠 Conceptual
advanced2:00remaining
Understanding three-valued logic with NULL
In SQL, what is the result of the expression
(NULL <> 5) in a WHERE clause filter?Attempts:
2 left
💡 Hint
Remember SQL uses three-valued logic: TRUE, FALSE, and UNKNOWN.
✗ Incorrect
Any comparison with NULL results in UNKNOWN, which acts like FALSE in WHERE filters, so the row is not selected.
📝 Syntax
advanced2:00remaining
Correct syntax to check for NULL in SQL
Which of the following SQL WHERE clauses correctly filters rows where the column
Price is NULL?Attempts:
2 left
💡 Hint
Think about the special keyword used to check NULL values.
✗ Incorrect
The correct syntax to check for NULL is using IS NULL. Using = NULL or != NULL is invalid or returns unknown.
❓ optimization
expert3:00remaining
Optimizing queries with NULL checks
You want to find all customers who have not placed any orders. The
Orders table has a nullable CustomerID column. Which query is most efficient and correct?A) SELECT * FROM Customers WHERE CustomerID NOT IN (SELECT CustomerID FROM Orders);
B) SELECT * FROM Customers WHERE CustomerID NOT IN (SELECT CustomerID FROM Orders WHERE CustomerID IS NOT NULL);
C) SELECT * FROM Customers WHERE CustomerID NOT EXISTS (SELECT 1 FROM Orders WHERE Orders.CustomerID = Customers.CustomerID);
D) SELECT * FROM Customers WHERE CustomerID IS NULL;
Attempts:
2 left
💡 Hint
Consider how NULLs affect NOT IN and EXISTS clauses.
✗ Incorrect
NOT IN with NULLs in subquery can cause no rows to be returned due to unknown comparisons. Using NOT EXISTS avoids this problem and is more efficient.