Oracle LISTAGG – How to De-Duplicate from LISTAGG

listaggoracleoracle-11g

I am using 11.2 version of oracle.
I want to de-duplicate from LISTAGG.

below is existing data in oracle db:

Speaker | Qualification | Product
P           A              P1
P           B              P2
P           C              P3
P           D              P1
P           E              P2
Q           A              P1
Q           B              P2
Q           C              P1

Want below data:

Spkeaker | Product
P           ;P1;P2;P3;
Q           ;P1;P2;

Can any one help please.

Best Answer

select
  speaker,
  listagg(product, ';')
    within group (order by product)
    as products 
from
  (
    select distinct speaker, product
    from existing_data
  ) t
group by speaker
order by speaker ;

Test at: dbfiddle.uk