Here is the query:
SELECT a.name as Employee, b.name as Manager from Employee as a
LEFT JOIN Employee as b
ON a.ManagerId = b.Id AND a.ManagerId IS NOT NULL
WHERE 1
It works on this table:
+----+-------+--------+-----------+
| Id | Name | Salary | ManagerId |
+----+-------+--------+-----------+
| 1 | Joe | 70000 | 3 |
| 2 | Henry | 80000 | 4 |
| 3 | Sam | 60000 | NULL |
| 4 | Max | 90000 | NULL |
+----+-------+--------+-----------+
As Idea this query shold show all Employers. A set of rows that have a.ManagerId = b.Id.
And everthing works fine, exept rows
Sam, NULL
Max, NULL
Why do these rows returns. If I set a.ManagerId is NOT NULL
in the ON
clause.