MySQL IFNULL

Profile picture for user arilio666

IFNULL returns the specified value if the expression returns null in a table. Else returns the expression.

Example:

SELECT IFNULL(NULL, "I Am Back")

We are going to use the employee_details table to demonstrate the IFNULL.

mysql select if null

  • Here we can see there is a null value in the reports_to column. Let us try to replace its value.
select * , IFNULL(reports_to,'37278') as null_fill from employee_details;

mysql ifnull

  • We can see here that the null value part of the column is filled up with the specified value alternate for that.
Tags