the (right) join is based on the condition, so:
>right outer join #d on #a.id = #d.id
means you will have records for #d, even if there are not matching records on #a.
note: I would NEVER mix LEFT and RIGHT joins in the same query, and I actually NEVER use right joins at all.
only LEFT joins ...
also, a COUNT(*) with LEFT/RIGHT joins usually makes no sense, because if you join left/right to count, you don't need the join at all ....
so, I would presumable rewrite the query to:
select ...
from #d
left outer join #a on #a.id = #d.id
left outer join #b on #a.id = #b.id
left outer join #c on #c.id = #a.id