title: SQL NOT EXISTS not returning expected results
body: <p>Using SSRS 2008 R2</p>
  
  <p>I'm having some problems working out how to look for records that are in one query and not another.</p>
  
  <p>I've tried NOT EXISTS, NOT IN and LEFT JOIN.</p>
  
  <p>When I try the sub query on its own it works fine, but when I join it to the first query with NOT EXISTS it returns no records (there should be around 5000 records returned).</p>
  
  <p>I found this post 
  <a href="https://stackoverflow.com/questions/1406215/sql-select-where-not-in-subquery-returns-no-results">SQL &quot;select where not in subquery&quot; returns no results</a> and whilst I'm not sure I understand all of the answers (!) I did try filtering out any nulls that either query returns. </p>
  
  <p>FYI it's not enough just to look for people who are in the first query where document type is not = 4 as I am doing something more complicated with additional columns I need for a table - I thought it would be easier for someone to point me in the right direction if I distilled the query down to that shown below.</p>
  
  <p>Thanks,
  Eileen</p>
  
  <pre><code>SELECT
    TblPeople.PeopleId
    ,TblPeople.FirstName
    ,TblPeople.Surname
  
  FROM 
  TblPeople
  
  WHERE TblPeople.PeopleId IS NOT NULL
  AND NOT EXISTS 
  
  (SELECT
    TblPeople.PeopleId 
  
  FROM
    TblPeople
    INNER JOIN TblDocument 
      ON TblDocument.DocumentPeopleId = TblPeople.PeopleId
  
  WHERE
    TblDocument.DocumentType = 4 
    AND TblPeople.PeopleId IS NOT NULL)
  </code></pre>