Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: How to flatten cols into rows
peteg_at_garlic.com (hedrew3) wrote in message news:<aad10be0.0401292322.7b6c320b_at_posting.google.com>...
> I have a single table, as follows:
>
> Col_A Col_B
> ------ ------
> Joe X
> Joe Y
> Joe Z
> Bob A
> Bob B
>
> and I need to have a result set that looks like:
>
> Joe X Y Z
> Bob A B
>
> The first column may have anywhere from 1 to max of 5 entries.
> Is this possible in SQL, or do I need to do it in PL/SQL?
>
> TIA
>
> Pete
Pete, yes this can be done in SQL. There is in fact more than one available method for transforming the row data into column data, but which methods are available to you depends on your version of Oracle.
This looks like a school assignment so I am going to recommend you search the newsgroup archives and look up PIVOT tables. There have been several posts with examples on this topic over the last few years.
You can search the archives via groups.google.com
HTH -- Mark D Powell -- Received on Fri Jan 30 2004 - 08:20:55 CST
![]() |
![]() |