0

I am building an application where if an admin logs in, he can see the entire Employee Details from all shores. Currently, I am using a recursive function to fetch it from DB which is making the application too slow. How to use MySQL hierarchy query to fetch all the direct and indirect employees under any admin employee and show the result in one go. Currently, more than 3k employee records are kept. Now for instance, if 1230 who is an admin logs in, he can see entire org employee ID including his direct reportees and indirect reportees as well.

My table name is: Employee_Table

Employee_ID      Manager_ID
123              1230
124              1230
125              1230
456              123
457              123
458              123
789              124
780              124
781              124
4512             125
4513             125
4514             125

..... and many more like this. (3k records). I referred to the other solutions in same type but they do seems to work in my case since the records are much higher.

Abhi
  • 41
  • 2
  • 10
  • What is your current attempt ? Share those details, including EXPLAIN results. Also, what is the expected output? – Madhur Bhaiya Sep 01 '18 at 06:31
  • @MadhurBhaiya I used one of the query in other types of question asked in the same category but they do not seems to work here. I need all the employee id if i use any manager id. – Abhi Sep 01 '18 at 17:32
  • select Employee_ID from (select * from Employee_Table order by Manager_ID,Employee_ID) products_sorted, (select @pv := '1230') initialisation where find_in_set(Manager_ID, @pv) and length(@pv := concat(@pv, ',', id)) – Abhi Sep 01 '18 at 17:34

0 Answers0