0

I am new to postgres.

My postgres table name is Employee consisting of following columns

1.empid(uuid)//unique id
2.name
3.designation('engineer', 'asst.engineer', 'hr')
4.reporting_available('yes','no')
5.reporting_to('emp ids')//mapping to another employee

if suppose in organisation employee structure is like in below image

enter image description here

I need query for getting the hierarchy of jenny till reporting available (no)

Expected output

Jenny -> Sam -> Uday -> Sanjay.

Since sanjay dont report to anyone we should stop hierarchy at sanjay.

The similar questions

Postgres query to get all the children ids

SQL query to get the list of supervisor hierarchy. employee --> supervisor --> supervisor

how can I get all ids starting from a given id recursively in a postgresql table that references itself?

did not have answer related to my question

Ratan Uday Kumar
  • 5,738
  • 6
  • 35
  • 54
  • the above duplicate question not working for me – Ratan Uday Kumar Jul 13 '18 at 08:55
  • WITH RECURSIVE subordinates AS ( SELECT empid, reporting_to, name FROM employee WHERE empid = 'Emp107' UNION SELECT e.empid, e.reporting_to, e.name FROM employee e INNER JOIN subordinates s ON s.reporting_to = e.empid ) SELECT * FROM subordinates; – Ratan Uday Kumar Jul 13 '18 at 09:09

0 Answers0