How to Check Empty or Null Data using MySQL Query?
If you want to check empty or null value with conditional statement like case when and if in table row with Mysql database. you like to check empty or null value form table then you have multiple way check that. first we check empty value with case when statement then following example.
Empty Check:
SELECT
(CASE WHEN COALESCE(email,'')!='' THEN email ELSE 'example@gmail.com' END) as test
FROM `customers`
---------------------OR----------------------
SELECT
(CASE COALESCE(email,'') WHEN '' THEN 'example@gmail.com' ELSE email END) as test
FROM `customers`
---------------------OR----------------------
SELECT
(IF(COALESCE(email,'')!='',email,'example@gmail.com')) as exp
FROM `customers`
Null Check:
SELECT
(CASE WHEN email IS NULL THEN 'example@gmail.com' ELSE email END) as test
FROM `customers`
---------------------OR----------------------
SELECT
(IF(email IS NULL,'example@gmail.com',email)) as exp
FROM `customers`
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Install MySQL in Ubuntu Server?
- Node JS CRUD with MySQL Tutorial Example
- How to Create a REST API using Node.js and MySQL?
- How to add 1 day to the date column in MySQL?
- MYSQL Query for Data between Two Dates Example
- How to Use MySQL View in Laravel?
- How to Get Last Record in Codeigniter?
- How to Execute MySQL Query in Laravel?
- How to fetch this week records in MySql ?
- How to Copy One Table Data into Another Table using MySQL?
- How to count unique domains from email address field in MySQL ?
- Which MySQL Datatype use for Store an IP Address?
- Mysql Hexadecimal Color Code Store in Binary Datatype Example