Question : I am a little confused how the right outer join on #d knows which table is to the right?


I am a little confused how the right outer join on #d knows which table is to the right?

select count (*) from
#a left outer join #b on #a.id = #b.id left outer join #c on #c.id = #a.id
right outer join #d on #a.id = #d.id

Answer : I am a little confused how the right outer join on #d knows which table is to the right?

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

Random Solutions  
 
programming4us programming4us