I have a database that has a users table with two different columns, "users_id" and "users_manager". Each user has a manager above him.
Here's the deal: I need to list all users related to a manager, but in a way similar to a family tree — meaning that I have to list the main manager and each user below him, and if the user below him also managers other users, I have to list them too.
Here's an example:
• The user "2" manages the user "7". "7" manages users "10" and "12". "10" manages users "15" and "16"; "12" manages users "17" and "18". I need a list that includes all these users above when I'm refering to user "2", including "2" itself.
usersManagedBy2 = [2, 7, 10, 12, 15, 16, 17, 18]
I can't figure a way to achieve that using JavaScript, NodeJS and MySQL. Can someone help me?