1

If I have a table that has two fields (client, service) and lets say the table look like this:

client | Service
  1    |   A
  1    |   B
  1    |   C
  2    |   A
  2    |   D

I want to do a select statement that I can have all services from each client so the result would look like this

client  | Service
  1     | A, B, C
  2     | A, D

Is it possible in SQL? I am using oracle 10g

Icaro
  • 14,585
  • 6
  • 60
  • 75

1 Answers1

2

You can use listagg in this case -

select client, 
       listagg(service, ', ') within group (order by service) as service 
from the_table 
group by client;

listagg can be used either as an aggregate function or as an analytic function. Read more from here- link

Samiul Al Hossaini
  • 980
  • 6
  • 12
  • 24