MySQL IFNULL "N/A" yields "item cannot be found in the collection" Error

mysql, sql

Solution

Your query is good, but your code is probably looking for a column name? Try an alias:

SELECT IFNULL(mem.address2,'N/A') AS address2 FROM members mem ...

Problem

I have been using IFNULL functions to convert NULL values to zeros in my SQL queries, like this: ``` SELECT IFNULL(mem.comment_count,0) FROM members... ``` This works fine. I am now trying to use the IFNULL function to convert NULL values to a string, "N/A", but I keep getting the error: "item cannot be found in the collection corresponding to requested name or ordinal": ``` SELECT IFNULL(mem.address2,'N/A') FROM members... ``` I even tried using COALESCE just incase it's an empty string instead of a NULL: ``` SELECT COALESCE(NULLIF(mem.address2, ''), 'N/A') FROM members... ``` But still throws the same error. Any ideas?

Original source