IFNULL is not working

0
    select IFNULL(valor_unit,0) from tb_itens where id = 3  

In the scenario where id = 3 does not exist in my table SELECT does not return '0' just keeps returning NULL, I can not find the problem. I have already tested with COALESCE , but it continues to return null.

    
asked by anonymous 01.09.2018 / 18:14

1 answer

5
  

In the scenario where id = 3 does not exist in my table, SELECT does not   return '0' just keeps returning NULL

For sure, the function will check the value of the field, but if you have already limited in where , not bringing what can be null because it does not exist, will not come the result.

The function isnull should be used when a value can come null, if remove where should bring the correct result.

    
01.09.2018 / 18:23