365 Days of Daily Coding: Day
It’s been a wild ride since I started working on this daily coding challenge. I have not been able to be consistent. As with any humans, there are days I just do not feel like it or that I wanna pore my limited resource over other burning matters. What’s really important to me is that I pick myself right after I am able to start again.
This is the sixth question from the SQL Interview prep series. These questions were taken from a LinkedIn post by Eric Webner. Do follow him if you haven’t yet as he shares useful and informative posts on data analytics and data science matters.
Now let’s dive straight into the question. There are three consideration to look out for when deciding to choose to use IFNULL vs CASE WHEN:
- IFNULL supports only one condition whereas CASE WHEN supports multiple conditions. You could have multiple nested IFNULL however, this leads me to my next point.
- For complex conditions, CASE WHEN eases readability than IFNULL functions.
- I would probably also determine the execution time for my syntax using each functions.
IFNULL
IFNULL(expression, value_if_null)
CASE WHEN
CASE WHEN expression THEN 'value'
WHEN expression THEN 'value'
WHEN expression THEN 'value'
END

Leave a comment