sql - Self-Relationship query with oracle (children doesn't have the same father) -


i'm trying work on query involving self-relationship table.

i have these rows:

id    parent_id  1     null 2     1 3     2 4     3 . . . 

the "children" doesn't share same father. each 'father' have 1 child. have id of last 'child'. (for example, have id = 4)..i'd this:

  1     null   2     1   3     2   4     3 

how can retrieve these rows, given parent id may not in sequential order.

thanks in advance.

oracle supports recursive queries:

select t.id, t.parent_id t  start t.id = 4 connect prior t.parent_id = t.id 

sqlfiddle here.


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -