MySQL: Typecasting NULL to 0

Use IFNULL(column, 0) to convert the column value to zero.

Alternatively, the COALESCE function will do the same thing: COALESCE(column, 0), except

  1. COALESCE is ANSI-compliant, IFNULL is not
  2. COALESCE takes an arbitrary number of columns/values and will return the first non-null value passed to it.

Leave a Comment