Categories: MySQL

Replace NULL values

Share

You can show the null values which represent the concept of missing or inapplicable information, with other values for better data representation.

Suppose we have a table as below:

Name Country
John India
Jane Australia
Tim [NULL]

So if you query from the database the null result will show the blank result.

You can replace NULL values by another value at run time.

SELECT name, 
       IF(country IS NULL,"No Country",country) country
FROM users;
Name Country
John India
Jane Australia
Tim No Country

MySQL also handles the null values directly using IFNULL function.

SELECT name, 
       IFNULL(country,"No Country") country
FROM users;

Recent Posts

Unveiling the Ultimate Car Cleaning Kit: Your Road to a Pristine Ride

Introduction: In order to stay clean, car care all in the world is not only…

7 hours ago

Oppo vs Vivo: The Race to be the Number One Smartphone in India

Oppo and Vivo are two smartphone makers in India that manufacture quality mobile phones at…

20 hours ago

10 Reasons Why Technology is Good for Education

Educational technology has been very helpful in the era of ever-advancing technology. It opens millions…

1 day ago

Chat GPT Login: Step-by-Step Guide for Beginners

Have you ever thought of a world where asking the Internet for information feels like…

1 day ago

The Sharp-Looking Guy: 5 Essential Tips for Men to Become Sharp

We've gotten so used to seeing men streetwear joggers, ripped jeans, and sleeveless shirts. Hair…

3 days ago

How to Use Your Wedding Jewellery In Unique Ways At Festivals

When it comes to festivals, the options for wedding jewellery are endless. You can go…

3 days ago