0
0
MySQLquery~5 mins

NULLIF function in MySQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the NULLIF(expr1, expr2) function do in MySQL?
It compares expr1 and expr2. If they are equal, it returns NULL. Otherwise, it returns expr1.
Click to reveal answer
beginner
What will NULLIF(5, 5) return?
It returns NULL because both values are equal.
Click to reveal answer
beginner
What will NULLIF('apple', 'orange') return?
It returns 'apple' because the two values are not equal.
Click to reveal answer
intermediate
Why is NULLIF useful in SQL queries?
It helps avoid division by zero or handle special cases by returning NULL when two values match, which can prevent errors or unwanted results.
Click to reveal answer
intermediate
How does NULLIF differ from a simple CASE statement?
While CASE can do many checks, NULLIF is a shortcut for returning NULL if two expressions are equal, making code shorter and clearer.
Click to reveal answer
What does NULLIF(10, 10) return?
ANULL
B10
C0
DError
If NULLIF('cat', 'dog') is used, what is the result?
A'dog'
BNULL
C'cat'
DError
Which of these is a common use of NULLIF?
ATo replace NULL values with zero
BTo return NULL when two values are equal
CTo concatenate two strings
DTo count rows in a table
What will SELECT NULLIF(0, 0) + 1; return?
AError
B1
C0
DNULL
Which SQL function is a shortcut for: CASE WHEN expr1 = expr2 THEN NULL ELSE expr1 END?
ANULLIF
BISNULL
CIFNULL
DCOALESCE
Explain how the NULLIF function works and give a simple example.
Think about comparing two values and what happens if they match.
You got /3 concepts.
    Describe a practical situation where using NULLIF can help avoid errors in SQL queries.
    Consider what happens if you divide by zero or want to ignore certain values.
    You got /3 concepts.