How To Check If Field is NULL or Empty with If Statement in MySQL?
Hello Friends,
This article will give you example of how to check if field is null or empty with if statement in MySQL?. I explained simply about check if field is null or empty with if statement example in MySQL. This tutorial will give you simple Check If Field is NULL or Empt SQL query.
In this post, You'll learn use MySQL check if column is null or empty in if statement. i will show you use of MySQL check if column is null or empty in case statement.
Here i will give you many example for MySQL check when null in if and empty field.
So let's see bellow solution:
Table: users_payment
So, let's see bellow solution:
Solution 1:
SELECT
id,
user_id,
charge,
IF(status IS NULL or status = '', 'PENDING', status) as status
FROM `user_payments`
Solution 2:
SELECT
id,
user_id,
charge,
CASE WHEN status IS NULL or status = ''
THEN 'PENDING'
ELSE status
END as status
FROM `user_payments`
Output:
It will help you...
- How to Increase max_connections in MySQL?
- How to Install the PHP PDO MySQL Extension on Ubuntu 22.04?
- How to Install PHP MySQL on Linux Ubuntu?
- How to Install LEMP Stack Nginx, MySQL, PHP on Ubuntu?
- How to Change MySQL Root User Password Ubuntu?
- PHP 8 MySQL Form Validation Example
- How to Select First Row Only in PHP MySQL?
- How To Backup MySQL Database Using PHP Example