Sample Header Ad - 728x90

Get all the users that are managed by a targeted manager

0 votes
2 answers
193 views
I have the following model: Table user: (id, name, direct_manager_id) Table customer: (id, name, managed_by_id) i.e. users can have another user as their direct manager, Customers can be managed by a user. My requirement is to create a simple select query that will retrieve all the customers that are managed by a specific user. moreover I would like that query to retrieve all the customers that are managed by users that their direct manager is that same user (1 level deep of direct management). and to retrieve all the customers that their direct manager is manged by a user that the direct manager of him is the targeted user (2nd level deep of direct management).... (to the nth level deep) Here is a picture of the hierarchy: targeted User / \ user1 user2 / \ / \ c1 c2 c3 user3 / c4 So the select query with the targeted user id will select the customers c1-c4
Asked by Urbanleg (375 rep)
Dec 23, 2014, 04:18 PM
Last activity: Jun 18, 2025, 07:06 PM