0
0
MySQLquery~10 mins

NULLIF function in MySQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to return NULL if the two values are equal.

MySQL
SELECT NULLIF(10, [1]);
Drag options to blanks, or click blank then click option'
A5
B10
C15
D20
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a different number than the first argument will return the first argument instead of NULL.
2fill in blank
medium

Complete the code to return the second value if the first is not equal to it.

MySQL
SELECT NULLIF(5, [1]);
Drag options to blanks, or click blank then click option'
ANULL
B5
C10
D5.0
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing the same value as the first argument will return NULL, not the first argument.
3fill in blank
hard

Fix the error in the code to correctly use NULLIF with column names.

MySQL
SELECT NULLIF(price, [1]) FROM products;
Drag options to blanks, or click blank then click option'
Aprice
BNULL
C'price'
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Putting column names in single quotes treats them as strings, causing errors or wrong results.
4fill in blank
hard

Fill both blanks to return NULL if quantity equals 0, else return quantity.

MySQL
SELECT NULLIF([1], [2]) AS result FROM inventory;
Drag options to blanks, or click blank then click option'
Aquantity
B0
CNULL
D'0'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '0' as a string instead of 0 as a number.
Using NULL as the second argument, which is invalid.
5fill in blank
hard

Fill all three blanks to return NULL if status equals 'inactive', else return status in uppercase.

MySQL
SELECT NULLIF(UPPER([1]), [2]) AS status_upper FROM users WHERE [3] = 'inactive';
Drag options to blanks, or click blank then click option'
Astatus
B'INACTIVE'
D'inactive'
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'inactive' in NULLIF comparison causes mismatch.
Using quotes incorrectly around column names.