In a table, there are 3 rows and 2 columns. I need to retrieve all the data, but instead of getting 3 rows of 2 columns each, I need to get one row of 6columns. Need to do that only in SQL !
As alluded to, it is critical to know the number of columns that will be necessary in the final result. Columns cannot be dynamically 'created' in a SQL statement.
IF the result set is 'fixed', then the following will work:
Of course, you could add more columns, to some arbitray max to handle an arbitrarily maximum number of rows. If the number of rows can be large, however, you would be much better off dynamically building the above statement in PL/SQL based on the number of rows expected.
Bookmarks