Home > Back-end >  MySQL - how to get NULL from `SELECT IF(NULL, 2, 3)`
MySQL - how to get NULL from `SELECT IF(NULL, 2, 3)`

Time:08-29

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?

CodePudding user response:

Use IF() combined with ISNULL():

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