I have a query successfully returning a max value but in certain cases there is no corresponding records so a null is returned. Is there a way to write the query so that a zero is returned instead?
MySQL Max() and Null values
Why would you want to return a 0 rather than a NULL? Although it is a very, very minute amount of data, and probably doesn't make a difference, I think NULL returns are easier to handle. So, say the value returned is stored in $result, you could to an if statement in the fashion if(!$result), or you could simply do this: if(!$result) { $result = 0; } to automatically do this. I am saying this because I don't think the functions included in MySQL can be rewritten...
4 months later
Hello,
try this :
select isnull(max(<field>), 0) from <table>
Bye