Is there a function equivalent to the Oracle's NVL in MySQL?

user833129 picture user833129 · Aug 30, 2011 · Viewed 32.2k times · Source

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 ?

Answer

Thilo picture Thilo · Aug 30, 2011

Use coalesce:

select coalesce(column_name, 'NULL VALUE') from the_table