In the outer query, you can replace a NULL
with a zero using the IFNULL()
function, e.g.
SELECT ...
, IFNULL(v.t1count,0) AS t1count
FROM ...
LEFT
JOIN ( SELECT ... AS t1count
...
) v
ON ...
The NULL you are getting returned by the outer query isn't from the inline view query. The NULL is a result of "no match" being found by the LEFT [OUTER] JOIN
operation.
If you are referencing v.t1count
in other expressions in the outer query, you can replace those references with NULLIF(v.t1count,0)
as well.