title: When I add a LEFT OUTER JOIN, the query returns only a few rows
body: <p>The original query returns 160k rows. When I add the LEFT OUTER JOIN:</p>
  
  <pre><code>LEFT OUTER JOIN Table_Z Z WITH (NOLOCK) ON A.Id = Z.Id
  </code></pre>
  
  <p>the query returns only 150 rows. I'm not sure what I'm doing wrong.</p>
  
  <p>All I need to do is add a column to the query, which will bring back a code from a different table. The code could be a number or a NULL. I still have to display NULL, hence the reason for the LEFT join. They should join on the "id" columns.</p>
  
  <pre><code>SELECT &lt;lots of stuff&gt; + the new column that I need (called "code").
  FROM 
      dbo.Table_A A WITH (NOLOCK)
  INNER JOIN 
      dbo.Table_B B WITH (NOLOCK) ON A.Id = B.Id AND A.version = B.version
  
  --this is where I added the LEFT OUTER JOIN. with it, the query returns 150 rows, without it, 160k rows.    
  LEFT OUTER JOIN 
      Table_Z Z WITH (NOLOCK) ON A.Id = Z.Id
  LEFT OUTER JOIN 
      Table_E E WITH (NOLOCK) ON A.agent = E.agent
  LEFT OUTER JOIN 
      Table_D D WITH (NOLOCK) ON E.location = D.location
                              AND E.type = 'Organization'
                              AND D.af_type = 'agent_location'
  INNER JOIN 
      (SELECT X , MAX(Version) AS MaxVersion 
       FROM LocalTable WITH (NOLOCK) 
       GROUP BY agemt) P ON E.agent = P.location AND E.Version = P.MaxVersion
  </code></pre>
  
  <p>Does anyone have any idea what could be causing the issue?</p>