Return 0 if field is NULL in MySQL
Question:
How to return 0 if field is NULL in MySQL? Answer:
SELECT IFNULL(order_value, 0) FROM order;
Description:
If you want to return a default value from a query if a filed value is NULL
in MySQL or MariaDB you can use the IFNULL
function.
Enter the desired column name as the first parameter and the chosen default value as the second.
Syntax:
IFNULL(fieldName, defaultValue)
Reference:
MySQL ifnull reference
Share "How to return 0 if field is NULL in MySQL?"
Related snippets:
Tags:
return value, default value, null, if null, mysql, mariadb, Technical term:
Return 0 if field is NULL in MySQL