MySQL set null value to zero


The function 'COALESCE' can simplify working with null values.
For Example, to treat null as zero, you can use:
select COALESCE(colname,0) from table where
COALESCE(colname,0) > 1;

in a date field, i used:
ORDER BY
(coalesce(TO_DAYS(date),TO_DAYS(CURDATE()))-TO_DAYS(CURDATE()))
to treat NULL as the current date.

ref.
http://dev.mysql.com/doc/refman/5.0/en/working-with-null.html

Popular posts from this blog

เทคนิค ชนะ เกมเศรษฐี 14 ตารวด!!! ( Let's get Rich )

Using Google Chrome Inspect Element to Analyze the website

Easy way to download whole youtube play list and convert them to mp3