Bird
Raised Fist0
SQLquery~20 mins

NULL in AND, OR, NOT logic in SQL - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
SQL NULL Logic Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate
1:30remaining
Output of AND with NULL
What is the result of the following SQL expression?

SELECT TRUE AND NULL AS result;
SQL
SELECT TRUE AND NULL AS result;
ASyntax Error
BTRUE
CFALSE
DNULL
Attempts:
2 left
💡 Hint
Remember that NULL means unknown in SQL logic.
❓ query_result
intermediate
1:30remaining
Output of OR with NULL
What is the result of this SQL expression?

SELECT FALSE OR NULL AS result;
SQL
SELECT FALSE OR NULL AS result;
ATRUE
BNULL
CFALSE
DRuntime Error
Attempts:
2 left
💡 Hint
Think about how OR behaves when one operand is unknown.
❓ query_result
advanced
1:30remaining
Output of NOT with NULL
What is the result of this SQL expression?

SELECT NOT NULL AS result;
SQL
SELECT NOT NULL AS result;
ASyntax Error
BFALSE
CNULL
DTRUE
Attempts:
2 left
💡 Hint
NOT reverses TRUE to FALSE and FALSE to TRUE, but what about NULL?
🧠 Conceptual
advanced
2:00remaining
Understanding NULL in complex AND/OR expressions
Consider the expression:

SELECT (TRUE OR NULL) AND FALSE AS result;

What is the output?
SQL
SELECT (TRUE OR NULL) AND FALSE AS result;
AFALSE
BTRUE
CNULL
DSyntax Error
Attempts:
2 left
💡 Hint
Evaluate the OR part first, then AND with FALSE.
🧠 Conceptual
expert
2:30remaining
Behavior of NULL in NOT combined with AND and OR
What is the result of this SQL expression?

SELECT NOT (FALSE AND NULL) OR (NULL AND TRUE) AS result;
SQL
SELECT NOT (FALSE AND NULL) OR (NULL AND TRUE) AS result;
ATRUE
BFALSE
CNULL
DRuntime Error
Attempts:
2 left
💡 Hint
Evaluate inside parentheses first, then apply NOT and OR.

Practice

(1/5)
1. What is the result of the SQL expression TRUE AND NULL?
easy
A. TRUE
B. NULL
C. FALSE
D. Error

Solution

  1. Step 1: Understand AND with NULL

    In SQL, AND returns FALSE if any side is FALSE. If one side is TRUE and the other is NULL, the result is NULL because the unknown value affects the outcome.
  2. Step 2: Apply to TRUE AND NULL

    Since the first operand is TRUE and the second is NULL, the result is NULL.
  3. Final Answer:

    NULL -> Option B
  4. Quick Check:

    TRUE AND NULL = NULL [OK]
Hint: AND with NULL returns NULL unless FALSE present [OK]
Common Mistakes:
  • Assuming TRUE AND NULL is TRUE
  • Confusing NULL with FALSE
  • Thinking NULL causes error
2. Which of the following is the correct SQL syntax to check if a column col is NOT NULL?
easy
A. col != NULL
B. col <> NULL
C. col IS NOT NULL
D. NOT col = NULL

Solution

  1. Step 1: Recall NULL comparison rules

    In SQL, you cannot use = or != to compare with NULL. Instead, use IS NULL or IS NOT NULL.
  2. Step 2: Identify correct syntax

    The correct way to check if col is not null is col IS NOT NULL.
  3. Final Answer:

    col IS NOT NULL -> Option C
  4. Quick Check:

    Use IS NOT NULL for null checks [OK]
Hint: Use IS NOT NULL, not != or <> [OK]
Common Mistakes:
  • Using != or <> to compare with NULL
  • Using NOT col = NULL which is invalid
  • Confusing NULL with empty string
3. Given a table Test with a column flag that can be TRUE, FALSE, or NULL, what is the result of this query?
SELECT * FROM Test WHERE flag OR FALSE;
medium
A. Rows where flag is TRUE
B. Rows where flag is TRUE or NULL
C. Rows where flag is TRUE or FALSE
D. No rows returned

Solution

  1. Step 1: Understand OR with FALSE

    In SQL, OR FALSE returns the value of the first operand because FALSE does not affect the OR result.
  2. Step 2: Evaluate flag OR FALSE

    If flag is TRUE, the expression is TRUE. If flag is FALSE, expression is FALSE. If flag is NULL, expression is NULL (unknown), which is treated as FALSE in WHERE filtering.
  3. Final Answer:

    Rows where flag is TRUE -> Option A
  4. Quick Check:

    flag OR FALSE = flag; WHERE filters TRUE only [OK]
Hint: OR FALSE returns first operand value [OK]
Common Mistakes:
  • Including NULL rows in result
  • Thinking OR FALSE always returns TRUE
  • Confusing OR with AND behavior
4. Consider this SQL WHERE clause:
WHERE NOT (col = NULL)

What is the problem with this condition?
medium
A. It always returns NULL (no rows match)
B. It always returns TRUE
C. It always returns FALSE
D. It causes a syntax error

Solution

  1. Step 1: Understand comparison with NULL

    In SQL, col = NULL always returns NULL (unknown), never TRUE or FALSE.
  2. Step 2: Apply NOT to NULL

    NOT NULL is still NULL, so the condition never evaluates to TRUE, filtering out all rows.
  3. Final Answer:

    It always returns NULL (no rows match) -> Option A
  4. Quick Check:

    NOT (col = NULL) = NULL, no matches [OK]
Hint: NOT NULL remains NULL, no rows pass filter [OK]
Common Mistakes:
  • Expecting NOT NULL to be TRUE
  • Using = NULL instead of IS NULL
  • Assuming syntax error occurs
5. You want to select rows from a table Employees where the ManagerID is either NULL or the employee is active (Active = TRUE). Which WHERE clause correctly handles NULL logic?
hard
A. WHERE ManagerID IS NOT NULL OR Active = TRUE
B. WHERE ManagerID = NULL OR Active = TRUE
C. WHERE NOT ManagerID = NULL AND Active = TRUE
D. WHERE ManagerID IS NULL OR Active = TRUE

Solution

  1. Step 1: Correctly check for NULL

    Use IS NULL to check if ManagerID is NULL. Using = NULL is invalid and returns NULL.
  2. Step 2: Combine conditions with OR

    The condition requires rows where ManagerID is NULL or Active is TRUE, so use OR between these checks.
  3. Final Answer:

    WHERE ManagerID IS NULL OR Active = TRUE -> Option D
  4. Quick Check:

    Use IS NULL and OR for correct logic [OK]
Hint: Use IS NULL, combine with OR for either condition [OK]
Common Mistakes:
  • Using = NULL instead of IS NULL
  • Using AND instead of OR
  • Using IS NOT NULL which is opposite
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