How to check empty or null in Mysql Query?

Share Me
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Today now in this tutorial i will show you how to check empty or null in mysql query. If we need to check an empty or null value with conditional statement on like case when and if in table row also with the Mysql database. So we like to check empty or null value form the table then we have the multiple way check that. At first we check empty value also with case when the 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`

Read Also : How to Open Link in New Window by using Javascript ?

Thanks for read. I hope it help you. For more you can follow us on facebook.

About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →