I was looking up the use of IFNULL() expression in db queries in Drupal and I found this module using it in HeartbeatStream::createQuery() (includes/heartbeatstream.inc).
// The user_access field holds the least access known. (NULL = HEARTBEAT_PUBLIC_TO_ALL). $access_expression = "LEAST ( IFNULL ( ha.access, " . HEARTBEAT_PUBLIC_TO_ALL . "), IFNULL ( hut.status, " . HEARTBEAT_PUBLIC_TO_ALL . "))";
IFNULL is MySQL specific. For portability, use COALESCE as it is generic and is part of standard SQL. Docs from Mysql - http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#functio... but it is the same function syntax for PostgreSQL, Oracle and SQL Server.