0
0
SQLquery~10 mins

COALESCE and NULLIF as CASE shortcuts in SQL - 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 the first non-null value between column1 and column2.

SQL
SELECT COALESCE(column1, [1]) AS result FROM table_name;
Drag options to blanks, or click blank then click option'
A'default'
Bcolumn3
CNULL
Dcolumn2
Attempts:
3 left
💡 Hint
Common Mistakes
Using a literal string instead of a column name.
Using NULL as the second argument which always returns NULL if column1 is NULL.
2fill in blank
medium

Complete the code to return NULL if column1 equals column2, otherwise return column1.

SQL
SELECT NULLIF(column1, [1]) AS result FROM table_name;
Drag options to blanks, or click blank then click option'
Acolumn2
Bcolumn3
C'value'
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing column1 with a literal instead of column2.
Using COALESCE instead of NULLIF.
3fill in blank
hard

Fix the error in the code to return the first non-null value among column1, column2, and 'N/A'.

SQL
SELECT COALESCE([1], column2, 'N/A') AS result FROM table_name;
Drag options to blanks, or click blank then click option'
Acolumn3
B'N/A'
Ccolumn1
DNULL
Attempts:
3 left
💡 Hint
Common Mistakes
Using a literal or NULL as the first argument instead of column1.
Putting 'N/A' before columns which prevents checking columns.
4fill in blank
hard

Fill both blanks to return 'Unknown' if column1 equals column2, else return column1 or 'Unknown' if column1 is NULL.

SQL
SELECT COALESCE(NULLIF(column1, [1]), [2]) AS result FROM table_name;
Drag options to blanks, or click blank then click option'
Acolumn2
B'Unknown'
Ccolumn3
DNULL
Attempts:
3 left
💡 Hint
Common Mistakes
Using NULL instead of 'Unknown' as fallback.
Comparing column1 with a wrong column.
5fill in blank
hard

Fill all three blanks to return the uppercase of column1 if UPPER(column1) is not equal to column2 and column1 is not NULL, else return 'DEFAULT'.

SQL
SELECT COALESCE(NULLIF([1], [2]), [3]) AS result FROM table_name;
Drag options to blanks, or click blank then click option'
AUPPER(column1)
Bcolumn2
C'DEFAULT'
Dcolumn1
Attempts:
3 left
💡 Hint
Common Mistakes
Using column1 instead of UPPER(column1).
Using NULL instead of 'DEFAULT' as fallback.