Good time of day! There is some table tb:
ID | PARENT_ID | LEV --------------------------- 10165 |10167 |0 10167 |10163 |0 10163 |10000 |2 10000 |null |2 The task is for all IDs to find the nearest PARENT_ID with LEV = 2. Nesting level can be any. For example, for ID = 10165 it will be 10163. The value for one id can be found by recursive query:
select ID from tb where LEV='2' start with ID='10165' connect by ID = prior PARENT_ID and rownum=1; But you need to find a single query for all IDs and display them in a new table: ID | PARENT_LEV2_ID Tell me how to do this?