Using IFNULL and COALESCE in MySQL
📖 Scenario: You work for a small online store. Some customers have missing phone numbers in the database. You want to create a report that shows a phone number for each customer. If the phone number is missing, you want to show a default message instead.
🎯 Goal: Build a MySQL query that uses IFNULL and COALESCE functions to replace missing phone numbers with a default message.
📋 What You'll Learn
Create a table called
customers with columns id, name, and phone.Insert 3 customers with exact data including one with a NULL phone number.
Write a query using
IFNULL to show the phone number or 'No phone provided' if NULL.Write a query using
COALESCE to show the phone number or 'No phone provided' if NULL.💡 Why This Matters
🌍 Real World
Handling missing data in customer contact information to improve reports and user experience.
💼 Career
Database developers and analysts often need to manage NULL values to ensure clean and meaningful data output.
Progress0 / 4 steps