MAX() is an analytic function, so you should only need it to reduce multiple results into a single value. It may be coercing NULL into a number, though. COALESCE(statement, value_if_statement_is_null) might achieve the same thing, and be easier to understand.