Our business as a tiered Salesman relation, sometimes called an omni-tier. Its 3 deep.
in english: Salesman-A-tier has people under them, we'll call them salesman-B-tier, and b-tier has salesman under them salesman-C-tier.
table:
id, name, agentId
1011, bob, 0
1012, jim, 1011
1013, tim, 1011
1014, sam, 1011
1015, dav, 1013
1016, kim, 1013
1017, sal, 1015
1018, vin, 1015
(the ID is the agents' Id, the field called agentId is that salesmans upstream agent)
what i need is a list of all the salesmen under (in this case bob or id=1011), 3 tiers deep.
i've gotten 2 levels deep but get throttled after that. figuring theres a better approach i cannot see myself, i'm asking for help.
my sql so far:
select c.id, c.name, c.agentId from salesmen s where s.agentId = 1011 or s.agentId = (select ss.agentId from salesmen ss where ss.id=s.agentid)
This gets me 2 tiers deep but i cannot get a third.
any help is appreciated. thanks in advance, Matthew