- Instant help with your Sql coding problems

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)   

Share "How to return 0 if field is NULL in MySQL?"
Tags:
return value, default value, null, if null, mysql, mariadb,
Technical term:
Return 0 if field is NULL in MySQL