The first version returns the
result where
value=compare_value.
The second version returns the result for the first condition
that is true. If there was no matching result value, the
result after ELSE is returned, or
NULL if there is no ELSE
part.

The return type of a CASE
expression is the compatible aggregated type of all return
values, but also depends on the context in which it is used.
If used in a string context, the result is returned as a
string. If used in a numeric context, the result is returned
as a decimal, real, or integer value.

Note

The syntax of the CASEexpression shown here differs slightly
from that of the SQL CASEstatement described in
Section 13.6.5.1, “CASE Syntax”, for use inside stored programs. The
CASE statement cannot have an
ELSE NULL clause, and it is terminated
with END CASE instead of
END.

The default result value of
IFNULL(expr1,expr2)
is the more “general” of the two expressions, in
the order STRING,
REAL, or
INTEGER. Consider the case of a
table based on expressions or where MySQL must internally
store a value returned by
IFNULL() in a temporary table: