Jesus Paradinas
Jesus Paradinas

Reputation: 187

Merge one column data in Oracle based on another two columns

I am trying to build a report in Oracle and I am struggling to group the data by two columns (client and user) and concatenate 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:

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

I am trying to 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?

Upvotes: 1

Views: 66

Answers (1)

Mureinik
Mureinik

Reputation: 312259

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

Upvotes: 1

Related Questions