When you are using left outer joins, the intention is that one of the tables is keeping all of its rows, regardless of matches in the other tables.
My preferred structure is to put this table first:
select . . .
from <really important table> t left outer join
. . .
This doesn't work if you have inner joins later in the from
clause, because these would filter out rows with no matches.
In terms of your query, I think the first does what you expect. The second happens to do what you want, because you are only joining on the id
column. But the structure is very dangerous. If one of your subsequent inner joins were on a column from #E
, then it would (inadvertently) change the left joins to inner joins.
So, put the inner joins first, then the left outer joins.