mysql if not null, 0 or ""

John Magnolia picture John Magnolia · Feb 5, 2013 · Viewed 8.2k times · Source
SELECT * 
  FROM table WHERE id IN ('21') 
   AND (content_id IS NULL OR content_id = 0 OR content_id = '')

Is there a shorter way of writing this condition.

I have a int() column that could be either: NULL, 0 or EMPTY.

Answer

Pablo Santa Cruz picture Pablo Santa Cruz · Feb 5, 2013

You can use IFNULL function in MySQL.

select ____
  from tbl
 where IFNULL(content_id, 0) = 0