0

For each ids, several names appear in several rows. How can I make all of them appear in a single row?

select 
      cli.client, stb.macaddres, stb.unica as card, 
      pro.name 
from 
      clientes cli
inner join boxes stb on stb.nuclient = cli.nuclient
inner join date.servicio ser on ser.ids = stb.ids
inner join date.producto pro on pro.proid = ser.serid
where 
      cli.client=7;

Unexpected Results :

client macaddress  única  name
7       xxxxxxxxx  56565 product1
7       xxxxxxxxx  56565 product2
7       xxxxxxxxx  56565 product3

Desired Results :

client  macaddress  única  name
 7       xxxxxxxxx  56565 product1, product2,product3`
dwir182
  • 1,539
  • 10
  • 20

1 Answers1

0

You can do listagg() as gordon said in comment you can read here about documentation ListAGG()

And for your query :

select 
     cli.client, stb.macaddres, stb.unica as card 
     LISTAGG(pro.name, ', ') WITHIN GROUP (ORDER BY pro.proid ASC) "Name"
from 
     clientes cli
inner join boxes stb on stb.nuclient = cli.nuclient
inner join date.servicio ser on ser.ids = stb.ids
inner join date.producto pro on pro.proid = ser.serid
where 
     cli.client = 7;
Group By
    cli.client, stb.macaddres, stb.unica
dwir182
  • 1,539
  • 10
  • 20