MySQL – how to get NULL from `SELECT IF(NULL, 2, 3)`


I am using mysql function if.
When I run SELECT IF(NULL, 2, 3), I got 3.

can I get NULL when first argument is NULL by changing this SQL?


Use IF() combined with ISNULL():

SELECT IF(ISNULL(NULL), 2, 3)  -- output is 2

Answered By – Tim Biegeleisen

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published