Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Merge one column data in Oracle based on another two columns

I am trying to build a report in Oracle and I am struggling grouping the data by two columns (client and user) and concatenating the other one (operation).

Basically I have this data:

Client Operation User
Client A 1 John Smith
Client A 2 John Smith
Client A 1 Peter Brown
Client B 3 Mike Kennedy

and this is the expected result:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Client Operation User
Client A 1;2 John Smith
Client A 1 Peter Brown
Client B 3 Mike Kennedy

I am trying tro group the data by the columns client and user by I get the error "not a group by expression".

Can anyone help me with the query?

Thanks a lot!

>Solution :

I think you’re looking for the listagg function:

SELECT   client,
         LISTAGG(operation, ',') WITHIN GROUP (ORDER BY operation),
         user
FROM     mytable
GROUP BY client, user
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading