Skip to content
Advertisement

Oracle split repeating rows into columns when joining 2 tables

I have 2 tables like this:

table_a

table_b

I want to join both the tables such that the resultant contains the repeating row values in col2 of table_a as columns. Each ID will not contain more than 3 table_a.col2 values. In this example, the result table would look like this :

result:

How can I achieve this? I know I can use the listagg() to aggregate all the rows into one column like this :

This would give me a result like this :

Advertisement

Answer

You can use conditional aggregation:

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement