Support needs a contact list that never shows a blank phone. Return every customer with display_name and a phone_label. When phone is NULL, the label must be the text unlisted. Keep row order by customer_id.
Requirements
Keep the supplied table and seed rows unchanged.
Return exactly display_name and phone_label.
Use COALESCE(phone, 'unlisted') AS phone_label.
Include every customer, including Grace.
Do not filter WHERE phone IS NOT NULL.
Order by customer_id ascending.
Example
Input
Keep the customers table, then select display_name and phone_label for every row.
NULL is not the string 'NULL' and it is not an empty string. CONCAT-style display would still be NULL if you add text to a missing phone. COALESCE returns the first non-null argument, so stored numbers pass through and a missing phone becomes a label the UI can show. The query still returns Grace; hiding her with WHERE phone IS NOT NULL would drop a customer who needs contact follow-up. ORDER BY customer_id makes the list match the seed order instead of depending on insertion accidents. The empty string '' would still be a value; this seed uses true NULL, which is the case COALESCE is for.
Why this pattern matters
Support lists that skip NULL phones look complete and are not. COALESCE turns missing into a label without turning a real number into text until display time.
Solution walkthrough
Select every customer, not only those with a phone.
Alias COALESCE(phone, 'unlisted') as phone_label.
Order by customer_id so Grace stays in the middle.
Common mistakes to avoid
WHERE phone IS NOT NULL, which hides Grace.
Comparing phone = NULL, which never matches.
Using IFNULL with a different label than unlisted.
What this exercise teaches
Reason about NULL as missing data
Replace NULL with COALESCE
Keep a stable ORDER BY on the key
A PRACTICAL PLAN
Work through Label customers who have no phone with intent.
Translate the contract.Turn the requirements into a short checklist before editing your-solution.sql.
Use the example as evidence.Predict the result for the supplied input, then add one boundary case such as an empty value, a limit, or unexpected input.
Review the implementation.Compare your choices against solution.sql only after a real attempt.
EXERCISE FAQ
Before you move on.
What does “Label customers who have no phone” teach?
This beginner SQL exercise focuses on Reason about NULL as missing data, Replace NULL with COALESCE, Keep a stable ORDER BY on the key. Its requirements define the exact behavior to implement before you write code.
How should I validate this SQL solution?
Start with the displayed example input and expected output, then test a boundary case suggested by the requirements. Open your-solution.sql and select Run code. The browser creates a fresh isolated SQLite database, executes the complete script, and compares its result rows with the expected report.
When should I open the reference solution?
Attempt Label customers who have no phone first. Then open the read-only solution file to compare the contract, edge-case handling, and implementation choices—not simply to copy the final code.