The documentation is your friend; you must read it!
It says:
IFNULL(expr1,expr2)
If expr1 not NULL , IFNULL() returns expr1 ; otherwise it will return expr2 .
And then a lot of examples. This is equivalent to using a ternary conditional with a comparison with NULL and a comparison object as the second operand; what not to use characters ? and : so that you have nothing to do with anything.
So in your case:
SELECT IFNULL(`id`, 0) FROM `table`
If you are desperate to provide three operands explicitly (why ?!), switch to IF :
SELECT IF(`id` IS NULL, 0, `id`) FROM `table`
Lightness Races in Orbit Dec 14 '11 at 2:46 p.m. 2011-12-14 14:46
source share