title: Simple PostgreSQL Self Join
body: <p>This is what my <code>employee</code> table looks like where <code>manager_id</code> is Foreign Key to the same table it references to <code>employee_id</code> and indicates which employee has manager and who is.</p>
  <pre><code> employee_id | first_name |  last_name  | manager_id
  -------------+------------+-------------+------------
             1 | Windy      | Hays        |
             2 | Ava        | Christensen |          1
             3 | Hassan     | Conner      |          1
             4 | Anna       | Reeves      |          2
             5 | Sau        | Norman      |          2
             6 | Kelsie     | Hays        |          3
             7 | Tory       | Goff        |          3
             8 | Salley     | Lester      |          3
  </code></pre>
  <p>I did self left join and the result was what was expected.</p>
  <pre><code>SELECT
    e.first_name || ' ' || e.last_name AS employee,
    m.first_name || ' ' || m.last_name AS manager
  FROM
    employee e
    LEFT JOIN employee m ON m.employee_id = e.manager_id;
  </code></pre>
  <pre><code>    employee     |     manager
  -----------------+-----------------
   Windy Hays      |
   Ava Christensen | Windy Hays
   Hassan Conner   | Windy Hays
   Anna Reeves     | Ava Christensen
   Sau Norman      | Ava Christensen
   Kelsie Hays     | Hassan Conner
   Tory Goff       | Hassan Conner
   Salley Lester   | Hassan Conner
  (8 rows)
  </code></pre>
  <p>But this query gives me</p>
  <pre><code>SELECT
    e.first_name || ' ' || e.last_name AS employee,
    m.first_name || ' ' || m.last_name AS manager
  FROM
    employee e
    LEFT JOIN employee m ON m.employee_id = e.manager_id;
  WHERE m.employee_id IS NULL;
  </code></pre>
  <pre><code>  employee  | manager
  ------------+---------
   Windy Hays |
  (1 row)
  </code></pre>
  <p>So I don't understand why it returns something instead of nothing.<strong>employee_id</strong> will never be a NULL...</p>
  <p><a href="http://sqlfiddle.com/#!17/6e6af/9" rel="nofollow noreferrer">http://sqlfiddle.com/#!17/6e6af/9</a></p>