Challenge - 5 Problems
NULLIF Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate1:30remaining
What is the output of NULLIF when values are equal?
Consider the query:
What is the value of
SELECT NULLIF(5, 5) AS result;
What is the value of
result?PostgreSQL
SELECT NULLIF(5, 5) AS result;
Attempts:
2 left
💡 Hint
NULLIF returns NULL if both arguments are equal.
✗ Incorrect
The NULLIF function returns NULL when the two arguments are equal. Since both are 5, the result is NULL.
❓ query_result
intermediate1:30remaining
What does NULLIF return when values differ?
What is the output of this query?
SELECT NULLIF('apple', 'orange') AS result;PostgreSQL
SELECT NULLIF('apple', 'orange') AS result;
Attempts:
2 left
💡 Hint
NULLIF returns the first argument if they are not equal.
✗ Incorrect
Since 'apple' and 'orange' are different, NULLIF returns the first argument 'apple'.
🧠 Conceptual
advanced2:00remaining
How does NULLIF behave with NULL arguments?
What is the result of this query?
SELECT NULLIF(NULL, NULL) AS result;
PostgreSQL
SELECT NULLIF(NULL, NULL) AS result;
Attempts:
2 left
💡 Hint
NULL compared to anything is unknown, but NULLIF treats NULL arguments specially.
✗ Incorrect
NULLIF returns NULL if the two arguments are equal. However, NULL compared to NULL is unknown, so they are not considered equal. Therefore, NULLIF returns the first argument, which is NULL.
❓ query_result
advanced2:00remaining
What is the output of NULLIF with expressions?
Evaluate the query:
SELECT NULLIF(10/2, 5) AS result;
PostgreSQL
SELECT NULLIF(10/2, 5) AS result;
Attempts:
2 left
💡 Hint
Calculate the first expression and compare to the second argument.
✗ Incorrect
10 divided by 2 is 5, which equals the second argument. NULLIF returns NULL when both arguments are equal.
📝 Syntax
expert2:30remaining
Which NULLIF usage causes a syntax error?
Identify the option that will cause a syntax error in PostgreSQL:
Attempts:
2 left
💡 Hint
Check the number of arguments NULLIF requires.
✗ Incorrect
NULLIF requires exactly two arguments. Option A provides only one argument, causing a syntax error.