0
0
SQLquery~20 mins

IS NULL vs equals NULL in SQL - Practice Questions

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
What is the output of this SQL query?
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;
AThe query will cause a syntax error.
BAll rows where <code>ManagerID</code> is NULL will be returned.
CAll rows where <code>ManagerID</code> is not NULL will be returned.
DNo rows will be returned because <code>= NULL</code> always evaluates to false or unknown.
Attempts:
2 left
💡 Hint
Remember that NULL means unknown, so comparing with = NULL does not work as expected.
query_result
intermediate
2:00remaining
Which query correctly finds rows where a column is NULL?
Given a table Orders with a column ShippedDate that can be NULL, which query returns all orders that have not been shipped yet?
ASELECT * FROM Orders WHERE ShippedDate IS NULL;
BSELECT * FROM Orders WHERE ShippedDate IS NOT NULL;
CSELECT * FROM Orders WHERE ShippedDate <> NULL;
DSELECT * FROM Orders WHERE ShippedDate = NULL;
Attempts:
2 left
💡 Hint
Use the special SQL syntax for checking NULL values.
🧠 Conceptual
advanced
2:00remaining
Why does WHERE column = NULL not work as expected in SQL?
Explain why the condition column = NULL does not return rows where column is NULL.
ABecause the syntax <code>= NULL</code> is invalid in SQL and causes a syntax error.
BBecause NULL is treated as a special marker for unknown, and any comparison with NULL returns unknown, not true.
CBecause NULL values are automatically converted to zero in comparisons.
DBecause the database engine ignores NULL values in WHERE clauses.
Attempts:
2 left
💡 Hint
Think about what NULL means in SQL.
📝 Syntax
advanced
2:00remaining
Which SQL query will cause a syntax error?
Given a table Products with a nullable column DiscontinuedDate, which query is invalid?
ASELECT * FROM Products WHERE DiscontinuedDate = NULL;
BSELECT * FROM Products WHERE DiscontinuedDate IS NOT NULL;
CSELECT * FROM Products WHERE DiscontinuedDate IS NULL;
DSELECT * FROM Products WHERE DiscontinuedDate <> '2023-01-01';
Attempts:
2 left
💡 Hint
Check if comparing with NULL using = is allowed.
optimization
expert
3:00remaining
Which query is optimized to find rows where LastLogin is NULL?
You want to find all users who never logged in. The Users table has an indexed nullable column LastLogin. Which query uses the index efficiently?
ASELECT * FROM Users WHERE LastLogin = NULL;
BSELECT * FROM Users WHERE NOT (LastLogin IS NOT NULL);
CSELECT * FROM Users WHERE LastLogin IS NULL;
DSELECT * FROM Users WHERE LastLogin <> LastLogin;
Attempts:
2 left
💡 Hint
Use the standard NULL check syntax for best performance.