Reprence Html CSS javascript PHP MySQL Bootsrap

MySQL IFNULL() and COALESCE() Functions

Look at the following "Products" table:

136

Suppose that the "UnitsOnOrder" column is optional, and may contain NULL values.

Look at the following SELECT statement:


137

In the example above, if any of the "UnitsOnOrder" values are NULL, the result will be NULL.

MySQL IFNULL() Function

The MySQL IFNULL() function lets you return an alternative value if an expression is NULL.

The example below returns 0 if the value is NULL:

138

MySQL COALESCE() Function

Or we can use the COALESCE() function, like this:

139