Return 0 if query result is null.