title: Oracle LISTAGG case return distinct values
body: <p>I am writing a ORACLE select statement with LISTAGG. It works but when I was validating the data, I saw duplicates like 1:1,1:1,2:2,2:2.</p>
  
  <p>I verified that the database do have duplicate. The query is for two tables in a one to many relationship. Below is a snippet of my query but I changed the column names etc.. </p>
  
  <p>how can I modified the following query to return unique values for each person?</p>
  
  <p>Thanks</p>
  
  <pre><code>SELECT Table1.PERSON_ID, 
         Table1.FIRST_NAME,
         Table1.MIDDLE_NAME,
         Table1.LAST_NAME,
  
  LISTAGG(case  
          when Table2.DESCRIPTION = '1' then '1:1'
          when Table2.DESCRIPTION = '2' then '2:2'
          when Table2.DESCRIPTION = '3' then '3:3'
          when Table2.DESCRIPTION = '4' then '4:4'
          when Table2.DESCRIPTION = '5' then '5:5'
          when Table2.DESCRIPTION = '6' then '6:6'
          when Table2.DESCRIPTION = '7' then '7:7'
          when Table2.DESCRIPTION = '8' then '8:8'
          when Table2.DESCRIPTION = '9' then '9:9'
  
  
        else ''
  
   end, ',')  
  WITHIN GROUP (ORDER BY Table2.DESCRIPTION )  
  
  FROM Table1
  LEFT JOIN Table2
  
  ON Table2.PERSON_ID = Table1.PERSON_ID
  GROUP BY Table1.PERSON_ID,Table1.FIRST_NAME,Table1.MIDDLE_NAME, Table1.LAST_NAME
  </code></pre>