Replace null with 0 in MySQL
Solution 1:
Yes, by using COALESCE
.
SELECT COALESCE(null_column, 0) AS null_column FROM whatever;
COALESCE goes through the list of values you give it, and returns the first non-null value.
Solution 2:
I am adding this answer because no one mentioned IFNULL
function
You can use IFNULL
SELECT IFNULL(column_name, 0) FROM table_name;
IFNULL
will return column's value (if it has something other than NULL
) otherwise second parameter passed (in this case 0
).