In MySQL, sometimes you don’t want NULL values to be returned as NULL
. Sometimes you want NULL values to be returned with a different value, such as “N/A”, “Not Applicable”, “None”, or even the empty string “”.
Fortunately there are several ways to do this in MySQL.
Here are four:
- The
IFNULL()
function - The
COALESCE()
function - The
IF()
function combined with theIS NULL
(orIS NOT NULL
) operator - The
CASE
expression combined with theIS NULL
(orIS NOT NULL
) operator
Examples of these options are below.