0
0
SQLquery~20 mins

WHERE with IS NULL and IS NOT NULL in SQL - 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
Find rows with NULL values
Given a table Employees with columns id, name, and manager_id (which can be NULL), which query returns all employees who do not have a manager assigned?
SQL
SELECT * FROM Employees WHERE manager_id IS NULL;
ASELECT * FROM Employees WHERE manager_id IS NOT NULL;
BSELECT * FROM Employees WHERE manager_id = NULL;
CSELECT * FROM Employees WHERE manager_id != NULL;
DSELECT * FROM Employees WHERE manager_id IS NULL;
Attempts:
2 left
💡 Hint
Remember that NULL is not equal to anything, even NULL itself.
query_result
intermediate
2:00remaining
Exclude rows with NULL values
Which query returns all rows from the Orders table where the shipped_date is known (not NULL)?
SQL
SELECT * FROM Orders WHERE shipped_date IS NOT NULL;
ASELECT * FROM Orders WHERE shipped_date != NULL;
BSELECT * FROM Orders WHERE shipped_date IS NULL;
CSELECT * FROM Orders WHERE shipped_date IS NOT NULL;
DSELECT * FROM Orders WHERE shipped_date = NULL;
Attempts:
2 left
💡 Hint
Use the correct syntax to filter out NULL values.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in NULL check
Which option contains a syntax error when trying to select rows where email is NULL in the Users table?
SQL
SELECT * FROM Users WHERE email IS NULL;
ASELECT * FROM Users WHERE email = NULL;
BSELECT * FROM Users WHERE email IS NULL;
CSELECT * FROM Users WHERE email IS NOT NULL;
DSELECT * FROM Users WHERE email != NULL;
Attempts:
2 left
💡 Hint
Check how NULL comparisons are done in SQL.
query_result
advanced
2:00remaining
Count rows with NULL values
What is the result of this query on the Products table counting rows where discount_price is NULL?
SQL
SELECT COUNT(*) FROM Products WHERE discount_price IS NULL;
AReturns the total number of products regardless of discount_price.
BReturns the number of products without a discount price.
CReturns zero because NULL values are ignored in COUNT.
DReturns an error because COUNT cannot be used with IS NULL.
Attempts:
2 left
💡 Hint
COUNT(*) counts all rows that match the WHERE condition.
🧠 Conceptual
expert
2:00remaining
Understanding NULL behavior in WHERE clause
Consider the query: SELECT * FROM Customers WHERE phone_number != '123-456-7890'; Which statement is true about rows where phone_number is NULL?
ARows with NULL phone_number are excluded because any comparison with NULL returns UNKNOWN.
BRows with NULL phone_number are included because NULL is not equal to '123-456-7890'.
CRows with NULL phone_number cause a runtime error in the query.
DRows with NULL phone_number are included only if IS NOT NULL is added.
Attempts:
2 left
💡 Hint
Think about how SQL treats NULL in comparisons.