0
0
MySQLquery~10 mins

IFNULL and COALESCE 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 the value of 'score' or 0 if it is NULL.

MySQL
SELECT IFNULL(score, [1]) AS result FROM games;
Drag options to blanks, or click blank then click option'
A0
BNULL
Cscore
D''
Attempts:
3 left
💡 Hint
Common Mistakes
Using NULL as the replacement value, which does not change NULL results.
Using the column name again instead of a default value.
2fill in blank
medium

Complete the code to return the first non-NULL value among 'nickname', 'username', or 'guest'.

MySQL
SELECT COALESCE(nickname, username, [1]) AS display_name FROM users;
Drag options to blanks, or click blank then click option'
A'username'
BNULL
Cnickname
D'guest'
Attempts:
3 left
💡 Hint
Common Mistakes
Using NULL as the last value, which does not provide a fallback.
Using column names instead of a string literal for the fallback.
3fill in blank
hard

Complete the code to return the value of 'price' or 100 if it is NULL.

MySQL
SELECT IFNULL(price, [1]) AS final_price FROM products;
Drag options to blanks, or click blank then click option'
A100
Bprice
CNULL
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using NULL as the replacement value, which does not change NULL results.
Using the column name again instead of a default value.
4fill in blank
hard

Fill both blanks to create a dictionary of words and their lengths only if length is greater than 3.

MySQL
SELECT word, LENGTH(word) AS length FROM words WHERE LENGTH(word) [1] [2];
Drag options to blanks, or click blank then click option'
A>
B<
C3
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' reverses the condition.
Using 5 instead of 3 changes the filter.
5fill in blank
hard

Fill all three blanks to select the first non-NULL email from 'email1', 'email2', or 'email3'.

MySQL
SELECT COALESCE([1], [2], [3]) AS contact_email FROM contacts;
Drag options to blanks, or click blank then click option'
Aemail1
Bemail2
Cemail3
Demail4
Attempts:
3 left
💡 Hint
Common Mistakes
Including a non-existent column like 'email4'.
Repeating the same column multiple times.