I have just started to learn hierarchical queries to solve problems. Most of the examples available are based on the condition that there is a specific parent and you can connect to it using prior.
However, I have a table structure like below where Column A is parent of Column B and Column B is parent of Column C.
| Column_A | Column_B | Column_C |
|---|---|---|
| SaaS | A Cloud | Test 1 |
| SaaS | A Cloud | Test 2 |
| SaaS | A Cloud | Test 3 |
| SaaS | B Cloud | Test 1 |
| SaaS | B Cloud | Test 2 |
| SaaS | C Cloud | Test 1 |
Based on the above table, I would like to see if there are any techniques to achieve the below results.
SaaS (Top-Level)
A Cloud (Level 2)
- Test 1 (Level 3)
- Test 2
- Test 3
B Cloud
- Test 1
- Test 2
C Cloud
I am unable to use the starts with due to multiple columns and no specified way of identifying Column_A as the distinct parent.
CREATE TABLE TAB1 (COLUMN_A,COLUMN_B,COLUMN_C) AS
SELECT 'SaaS','A Cloud','Test 1' FROM DUAL
UNION ALL
SELECT 'SaaS','A Cloud','Test 2' FROM DUAL
UNION ALL
SELECT 'SaaS','A Cloud','Test 3' FROM DUAL
UNION ALL
SELECT 'SaaS','B Cloud','Test 1' FROM DUAL
UNION ALL
SELECT 'SaaS','B Cloud','Test 2' FROM DUAL
UNION ALL
SELECT 'SaaS','C Cloud','Test 1' FROM DUAL
select TAB1.*,LEVEL from TAB1
START WITH COLUMN_A='SaaS'
connect by prior COLUMN_B = COLUMN_A AND COLUMN_C= COLUMN_B
Any ideas on how to achieve this?