Reputation:
I'm selecting the max of a column from a table. But there is one problem: if there are no rows in the table, it returns null.
I want to use a function which will return a certain value if the result is null. For example with Oracle there is the NVL
function which gives a certain value if the column is null. Is there an equivalent function in MySQL ?
Upvotes: 31
Views: 61909
Reputation: 11
or you can use IFNULL(expr1,expr2)
If expr1 is not NULL, IFNULL() returns expr1; otherwise it returns expr2.
select IFNULL(column_name, 'NULL VALUE') from the_table;
taken from: https://dev.mysql.com/doc/refman/8.0/en/flow-control-functions.html#function_ifnull
Upvotes: 1