Reputation: 1
col1 | col2 |
---|---|
A | 1 |
B | 2 |
C | 3 |
col1 | col2 |
---|---|
1 | x |
2 | y |
3 | z |
col1 | col2 |
---|---|
x | test1 |
x | test2 |
x | test3 |
y | test4 |
y | test5 |
z | test6 |
z | test7 |
So my requirement is I need to get the result as
col1 | col2 |
---|---|
A | test1,test2,test3 |
B | test4,test5 |
C | test6, test7 |
can some one help, there is relation between the tables. I am using Oracle 19c
Thank you.
Upvotes: 0
Views: 232
Reputation: 1300
Here is what you are looking for :
SELECT
A.col1,
LISTAGG(C.col2, ',') WITHIN GROUP (ORDER BY C.col2) "col2"
FROM A
JOIN B on A.col2 = B.col1
JOIN C on B.col2 = C.col1
GROUP BY A.col1
Upvotes: 0