I think my problem can be solved with a 'recursive query', but since MySQL doesn't support recursive queries could some suggest me as to how to go about with this?.
Here's an example of what I need to do:
Input Table Employee:
Role | Parent_Role| Person | Geo| Region |District
----------------------------- -----------------------
Rep-1 DM-1 Lou Gertsner AME West CA
Rep-2 DM-1 Steve Ballmer AME West CA
DM-1 RVP-1 Marc Benioff AME West CA
RVP-1 GEO-1 Ray Ozzie AME West Null
WW Null Larry Ellison AME Null Null
GEO-1 WW Bill Gates AME Null Null
Rep-3 DM-1 Vinod Khosla AME West CA
Rep-4 DM-1 Marc Benioff AME West CA
Output Table
WW_Employee | Geo_Employee | Region_Employee | District_Employee|Role Employee Geo | Region | District |
--------------------------- ----------------------- ------------------------------------
Larry Ellison Bill Gates Ray Ozzie Marc Benioff Rep-1 Lou Gertsner AME West CA
Larry Ellison Bill Gates Ray Ozzie Marc Benioff Rep-2 Steve Ballmer AME West CA
Larry Ellison Bill Gates Ray Ozzie Marc Benioff DM-1 Marc Benioff AME West CA
Larry Ellison Bill Gates Ray Ozzie Null RVP-1 Ray Ozzie AME West Null
Larry Ellison Null Null Null WW Larry Ellison Null Null Null
Larry Ellison Bill Gates Null Null GEO-1 Bill Gates AME Null Null
Larry Ellison Bill Gates Ray Ozzie Marc Benioff Rep-3 Vinod Khosla AME West CA
Larry Ellison Bill Gates Ray Ozzie Marc Benioff Rep-4 Marc Benioff AME West CA
Using the Input Table , I want to create a role table(Output Table) that lists (in separate columns by role type) the managers in the hierarchy for every employee. The role is the unique key and the parent role defines the hierarchy in the input table. I'll appreciate your help in this!