March 3, 2011

MySQL alternative to MSSQL''s isNull()

I was looking for a way to do isNull() in MySQL the other day, for those that don’t know this means you can do something like:

SELECT isNull(mycolumn, 'blah') FROM myTable;

If the value in mycolumn is NULL, then ‘blah’ is returned, this can of course be any string literal/numeric value you want. MySQL doesn’t have isNull() but it does have ifNull() which is basically the same.

SELECT ifNull(mycolumn, 'blah') FROM myTable;

© Michael Sharman 2017