Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Concatenate few column values from multiple rows and bring the non aggregated column(pick anyone) va

1002123Sep 28 2017 — edited Sep 29 2017

Hi All,

My Oracle version:

Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

PL/SQL Release 11.2.0.4.0 - Production

The following is an example:

Table A

PID  ID   Description           

A     1      Have         

A     2      a nice day.  

B     3      Nice         

B     4      Work.      

C     5      Yes          

C     6      we can   

C     7      do   

C     8      this work!   

Output of the SQL should be:

PID  Description                               ID

A     Have a nice day.                         1

B     Nice Work.                                  3

C     Yes we can do this work!            5

or

PID  Description                               ID

A     Have a nice day.                         2

B     Nice Work.                                  3

C     Yes we can do this work!            7

Note: The ID column may have any value from the group.

I am using LISTAGG and my sample SQL is:

SELECT PID, LISTAGG(Description, ' ') WITHIN GROUP (ORDER BY NULL) Description

FROM A

GROUP BY PID;

I am not sure and need help on how to bring ID in the sample output.

This post has been answered by 1002123 on Sep 28 2017
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 27 2017
Added on Sep 28 2017
7 comments
476 views