Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Remove/distinct duplicates on listagg - oracle

c35ca562-ab90-473d-bece-3b3a047d3767Feb 20 2020 — edited Feb 20 2020

I'm using the oracle-xe 11g version and I have the below sql code that I aggregation the course code, but the output has duplicates.

SELECT

    b.alu_cpf            AS login,

    b.alu_nomeco         AS nome_completo,

    b.alu_emailpessoal   AS email,

    LISTAGG(d.cur1codigo, ', ') WITHIN GROUP (ORDER BY d.cur1codigo) AS cod_curso,

    LISTAGG(d.cur1nomeco, ', ') WITHIN GROUP (ORDER BY d.cur1nomeco) AS nome_curso,  

    TO_CHAR(b.alu_sexo, '9') AS sexo,

    a.alu_codigo AS matricula,

    b.alu_dtnascimento,  AS data_nascimento

FROM

    matricula_curr_dis              a

    INNER JOIN aluno                b ON b.alu_codigo = a.alu_codigo

    INNER JOIN dis01                c ON a.dis1codigo = c.dis1codigo

    INNER JOIN CUR01                d ON a.cur1codigo = d.cur1codigo

GROUP BY

    b.alu_cpf,

    b.alu_nomeco,

    b.alu_emailpessoal,

    a.alu_codigo,

    b.alu_sexo,

    b.alu_dtnascimento

ORDER BY

    nome_completo

Data:

login      | nome      | email  |       cod_curso
12345        fulano      xxxx      cod1, cod1, cod1, cod2

How I can distinct the cod_curso so it can look like this?

login      | nome      | email       |  cod_curso
12345       fulano       xxxx           cod1, cod2

This post has been answered by L. Fernigrini on Feb 20 2020
Jump to Answer
Comments
Post Details
Added on Feb 20 2020
7 comments
744 views