views:

62

answers:

1

Hello,

I am using postgresql. I have the table as like below

parent_id    child_id
----------------------
101       102
103       104
104       105
105       106   

I want to write a sql query which will give the final parent of input.

i.e suppose i pass 106 as input then , its output will be 103.

(106 --> 105 --> 104 --> 103)
+3  A: 

Look here: With Queries

Bandpay