Salesperson table looks like this:
SalespersonID Salesperson Supervisor Department
2 Jundy Yes 2
3 Harris Yes 1
4 Griffin No 1
5 Jameson Yes 3
6 Cary No 2
So I know that if I were to run a self-join on this table to see who is the boss of who, I should see, in this short table, only two returns....Jundy is the boss of Cary, and Harris is the boss of Griffin. Jameson has no subordinates. The self join is:
SELECT S.Salesperson, S.Department, S1.Salesperson AS Supervisor
FROM Salesperson AS S INNER JOIN Salesperson AS S1 ON (S.Department=S1.Department)
AND (S.SalespersonID <> S1.SalespersonID)
WHERE S1.SalespersonID = (Select SalespersonID from Salesperson Where Department
= S1.Department And Supervisor = True);
and i get:
Salesperson Department Supervisor
Cary 2 Jundy
Griffin 1 Harris
which i know is true.