ItSolutionStuff.com

How to Check Empty or Null Data using MySQL Query?

By Hardik Savani β€’ January 27, 2023
PHP β€’ MySql

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`

Tags: MySql
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

πŸ“Ί Subscribe on YouTube