ifnull handle null value- tricky part


  • 1
    S

    first time using ifnull function. the first answer below passed all test cases, but I don't understand why the second way did not. second one outputs empty but not null value when there is no max value with count =1. Can anyone help me understand ifnull function better? Thanks.

    select ifnull( (select num from ( select num  
    from number
    group by num
    having count(num) =  1
    order by num desc 
    limit 1
    ) as maxnum)  , null) as num
    
    select ifnull( num, null) as num
    from ( select num  
    from number
    group by num
    having count(num) =  1
    order by num desc 
    limit 1) as maxnum 
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.