Bird
Raised Fist0
MySQLquery~20 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What does the SQL condition column_name IS NULL check for in a table?
easy
A. It checks if the column value is missing or empty.
B. It checks if the column value is zero.
C. It checks if the column value is a blank string.
D. It checks if the column value is greater than zero.

Solution

  1. Step 1: Understand the meaning of NULL in SQL

    NULL means the value is missing or unknown, not zero or empty string.
  2. Step 2: Analyze the condition IS NULL

    This condition returns true only when the column has no value (NULL).
  3. Final Answer:

    It checks if the column value is missing or unknown. -> Option A
  4. Quick Check:

    IS NULL means missing value check [OK]
Hint: IS NULL means value is missing, not zero or empty [OK]
Common Mistakes:
  • Confusing NULL with zero or empty string
  • Using = NULL instead of IS NULL
  • Thinking NULL means zero
2. Which of the following is the correct syntax to select rows where the column email is NOT NULL?
easy
A. SELECT * FROM users WHERE email IS NOT NULL;
B. SELECT * FROM users WHERE email = NOT NULL;
C. SELECT * FROM users WHERE email != NULL;
D. SELECT * FROM users WHERE NOT email = NULL;

Solution

  1. Step 1: Recall correct syntax for NOT NULL check

    In SQL, to check for NOT NULL, use IS NOT NULL.
  2. Step 2: Evaluate each option

    SELECT * FROM users WHERE email IS NOT NULL; uses correct syntax. Others use invalid or incorrect operators with NULL.
  3. Final Answer:

    SELECT * FROM users WHERE email IS NOT NULL; -> Option A
  4. Quick Check:

    Use IS NOT NULL to check non-missing values [OK]
Hint: Use IS NOT NULL, not = or != with NULL [OK]
Common Mistakes:
  • Using = NULL or != NULL instead of IS NULL/IS NOT NULL
  • Forgetting IS keyword
  • Using NOT email = NULL which is invalid
3. Given the table orders with columns order_id and shipped_date, what will this query return?
SELECT order_id FROM orders WHERE shipped_date IS NULL;
medium
A. All orders that have a shipped date recorded.
B. All orders that have not been shipped yet.
C. All orders with shipped_date equal to zero.
D. Syntax error due to IS NULL usage.

Solution

  1. Step 1: Understand what IS NULL filters

    The condition shipped_date IS NULL selects rows where shipped_date is missing.
  2. Step 2: Interpret the meaning in context

    Missing shipped_date means the order has not been shipped yet.
  3. Final Answer:

    All orders that have not been shipped yet. -> Option B
  4. Quick Check:

    IS NULL finds missing shipped dates = unshipped orders [OK]
Hint: IS NULL finds missing data, here unshipped orders [OK]
Common Mistakes:
  • Thinking IS NULL returns shipped orders
  • Confusing NULL with zero or empty string
  • Assuming syntax error with IS NULL
4. You wrote this query but it returns no rows:
SELECT * FROM employees WHERE manager_id = NULL;

What is the error and how to fix it?
medium
A. Add quotes around NULL like = 'NULL'.
B. Change manager_id to IS NOT NULL.
C. Use IS NULL instead of = NULL to check for NULL values.
D. Use != NULL to find rows with NULL.

Solution

  1. Step 1: Identify incorrect NULL comparison

    Using = NULL always returns false because NULL is not equal to anything.
  2. Step 2: Correct syntax to check NULL

    Use IS NULL to check for NULL values properly.
  3. Final Answer:

    Use IS NULL instead of = NULL to check for NULL values. -> Option C
  4. Quick Check:

    Use IS NULL, not = NULL, for NULL checks [OK]
Hint: Always use IS NULL, never = NULL for missing values [OK]
Common Mistakes:
  • Using = NULL or != NULL instead of IS NULL/IS NOT NULL
  • Adding quotes around NULL
  • Confusing IS NULL with IS NOT NULL
5. You want to find customers who have provided a phone number but no email. Which query correctly uses IS NULL and IS NOT NULL to do this?
SELECT * FROM customers WHERE phone IS NOT NULL AND email IS NULL;
hard
A. This query has syntax errors with IS NULL usage.
B. This query returns customers missing both phone and email.
C. This query returns customers with both phone and email.
D. This query returns customers with phone and missing email.

Solution

  1. Step 1: Analyze the conditions

    phone IS NOT NULL selects customers who provided a phone number.
  2. Step 2: Check the email condition

    email IS NULL selects customers who did not provide an email.
  3. Step 3: Combine conditions with AND

    Both conditions together find customers with phone but no email.
  4. Final Answer:

    This query returns customers with phone and missing email. -> Option D
  5. Quick Check:

    IS NOT NULL and IS NULL combined filter correctly [OK]
Hint: Combine IS NOT NULL and IS NULL with AND for mixed filters [OK]
Common Mistakes:
  • Mixing AND with OR incorrectly
  • Using = NULL instead of IS NULL
  • Confusing which column to check for NULL
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard