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 ?
Use coalesce:
select coalesce(column_name, 'NULL VALUE') from the_table
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With