0
0
SQLquery~10 mins

COALESCE for NULL handling 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 'email' and 'phone'.

SQL
SELECT COALESCE([1], phone) AS contact FROM users;
Drag options to blanks, or click blank then click option'
Aphone
Bname
Caddress
Demail
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'phone' as the first argument will change the order of preference.
Using a column not in the SELECT list.
2fill in blank
medium

Complete the code to replace NULL 'salary' values with 0.

SQL
SELECT employee_id, COALESCE(salary, [1]) AS salary FROM employees;
Drag options to blanks, or click blank then click option'
A0
BNULL
C-1
D1000
Attempts:
3 left
💡 Hint
Common Mistakes
Using NULL again does not change the value.
Using a negative number might be confusing.
3fill in blank
hard

Fix the error in the code to return the first non-null value among 'nickname', 'firstname', and 'lastname'.

SQL
SELECT COALESCE(nickname, [1], lastname) AS display_name FROM contacts;
Drag options to blanks, or click blank then click option'
Amiddlename
Bfirstname
Cnickname
Dlastname
Attempts:
3 left
💡 Hint
Common Mistakes
Repeating 'lastname' twice.
Using a column not in the table.
4fill in blank
hard

Fill both blanks to return the first non-null value among 'city', 'state', and 'country'.

SQL
SELECT COALESCE([1], [2], country) AS location FROM addresses;
Drag options to blanks, or click blank then click option'
Acity
Bzipcode
Cstate
Dregion
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'zipcode' or 'region' which are not in the preferred order.
Swapping the order of 'city' and 'state'.
5fill in blank
hard

Fill all three blanks to return the first non-null value among 'home_phone', 'mobile_phone', and 'work_phone'.

SQL
SELECT COALESCE([1], [2], [3]) AS primary_phone FROM contacts;
Drag options to blanks, or click blank then click option'
Amobile_phone
Bhome_phone
Cwork_phone
Dfax_number
Attempts:
3 left
💡 Hint
Common Mistakes
Including 'fax_number' which is not a phone contact.
Changing the order of phone numbers.