Skip to content
Advertisement

Make Entire Result set into a Single Row

i have to convert the entire result in Oracle into a single row result set with different column names

I have tried with some self joins but not appears to be working .

Expected output

][1]

Expected here

Advertisement

Answer

Give each row a unique number and then PIVOT:

Oracle Setup:

Query:

Output:

    SSN_1 | FIRST_NAME_1 | LAST_NAME_1 |     SSN_2 | FIRST_NAME_2 | LAST_NAME_2 |     SSN_3 | FIRST_NAME_3 | LAST_NAME_3
--------: | :----------- | :---------- | --------: | :----------- | :---------- | --------: | :----------- | :----------
123456789 | VKP          | KKO         | 987654321 | ABC          | XYZ         | 332211456 | PQR          | GHJ        

db<>fiddle here

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