I have a below "User_Info". It carries all user info and the ID of the company that each user belongs to.
User_Id | User_Name | Company_Id
--------+-----------+--------------
1002 | User1 | 113
1003 | User2 | 114
1004 | User3 | 111
I have another table "Company" which has Company Information and its associated Parent Company.
id | Company_Name | Parent_Company_Id
----+-----------------+------------------
110 | WALMART | NULL
111 | WALMART TEXAS | 110
112 | WALMART DALLAS | 111
113 | WALMART HOUSTON | 111
114 | WALMART KATY | 113
How do I get the below output? The Company_id in the User_Info table should list all the hierarchical companies under that Company_id.
user_id | company_id
---------+--------------
1002 | 113
1002 | 111
1002 | 110
1003 | 114
1003 | 111
1003 | 110
1004 | 111
1004 | 110