Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Hierarchical query to combine two Column groupings

Sat NowMay 2 2025 — edited May 2 2025

Hi there,

I would like to know if anyone knows a way to solve the problem below with a SQL/PLSQL.

I have group1 and group2 both are interrelated:

The idea is to start from this dataset:

WITH T AS 
(
  SELECT 'A' AS GROUP1, 100 AS GROUP2 FROM DUAL UNION
  SELECT 'A' AS GROUP1, 101 AS GROUP2 FROM DUAL UNION
  SELECT 'B' AS GROUP1, 100 AS GROUP2 FROM DUAL UNION
  SELECT 'B' AS GROUP1, 102 AS GROUP2 FROM DUAL UNION
  SELECT 'C' AS GROUP1, 103 AS GROUP2 FROM DUAL UNION
  SELECT 'C' AS GROUP1, 104 AS GROUP2 FROM DUAL UNION
  SELECT 'D' AS GROUP1, 101 AS GROUP2 FROM DUAL UNION
  SELECT 'E' AS GROUP1, 104 AS GROUP2 FROM DUAL UNION
  SELECT 'F' AS GROUP1, 105 AS GROUP2 FROM DUAL 
)
SELECT * FROM T;

Expected OUPUT:

This seems to me like something that could be solved with a hierarchical query, but I could not get my head around it to solve the problem.

Hope one of you guys can help me on this.

Cheers.

Comments
Post Details
Added on May 2 2025
8 comments
282 views