search

Home  >  Q&A  >  body text

How to get NULL from `SELECT IF(NULL, 2, 3)` MySQL method

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

When the first parameter is NULL, by changing this SQL, can I get NULL?

P粉998920744P粉998920744280 days ago335

reply all(1)I'll reply

  • P粉450079266

    P粉4500792662024-02-22 16:03:52

    Use IF() with ISNULL():

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

    reply
    0
  • Cancelreply