Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: How to flatten cols into rows

Re: How to flatten cols into rows

From: Mark D Powell <Mark.Powell_at_eds.com>
Date: 30 Jan 2004 06:20:55 -0800
Message-ID: <2687bb95.0401300620.5a379b89@posting.google.com>


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

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US