I have the following table:
|fk ID|value | val id|
| 1 | val11| 1 |
| 1 | val12| 2 |
| 2 | val21| 1 |
| 2 | val22| 2 |
I want to transpose it to:
| fk ID | val1Title | val2Title |
| 1 | val11 | val12 |
| 2 | val21 | val22 |
Ive added an ID column to the top table which is used to order so we know that val11 is in the first column because it has an id less that val12.
I have an oracle DB and I think I need to pivot. I've found a couple of articles on it (e.g. Transposing Table) although it seems to be a lot of work for the pivot. Is this the easiest way?
How can I easily transpose? Im using Oracle 11g so am happy to use Oracle specific functions. I've used ListAgg
but that combines the columns. I want to columns separate though.
EDIT: The design of the original table is not normalised at the moment because this is actually the result of quite a complicated query.