How to SQL query through a row hierarchy?

by Holden   Last Updated March 14, 2019 20:26 PM

Suppose I have the following table structure, in an Oracle database, where PARENT references another row in the same table.

  id  | parent
  1   | null
  2   | 1
  3   | 2
  4   | 3
  5   | null
  6   | 5
  7   | 6

How could I query so that each row gets me the end of the sequence. That is I'd like to see this end result:

  id  | end_parent
  1   | 4
  2   | 4
  3   | 4
  4   | 4
  5   | 7
  6   | 7
  7   | 7


Related Questions



Oracle - xmlindex slows down the insert operation

Updated February 17, 2018 04:26 AM


Need the latest date from 2 columns in Oracle

Updated March 01, 2017 02:26 AM