title: Remove duplicate values from a listagg in oracle
body: <p>I have used <code>listagg</code> to concat and list books along with the supplementary books name.</p>
  
  <pre><code>SELECT DISTINCT SUBSTR(LISTAGG(',-'||B1.BOOK_NO||','||B1.BOOK_NAME||','||A.AUTHOR_NAME||',-'||B2.BOOK_NO||','||B2.BOOK_NAME)   WITHIN GROUP (ORDER BY B2.BOOK_NO),2) 
  FROM BOOK_LIST B1
  INNER JOIN AUTHORS A ON A.AUTHOR_NO=B1.AUTHOR_NO
  INNER JOIN SUPPLEMENTARY B2 ON B2.BOOK_NO = B1.BOOK_SUP_NO
  WHERE B1.SEQ = 123;
  </code></pre>
  
  <p>But since the number of supplementary books are more i get the main book name repeatedly.</p>
  
  <p>Is there a way to remove the duplicate main book name and number.</p>
  
  <p>My ouput is like this </p>
  
  <p><code>-99,Anders Carlson ,-109,John Stuart,-99,Anders Carlson ,-47,James Anderson</code></p>
  
  <p>Here the value 99 is repeated i want only one 99.</p>
  
  <p>Desired Output:</p>
  
  <p><code>-99,Anders Carlson ,-109,John Stuart,-47,James Anderson</code></p>
  
  <p>DB data:</p>
  
  <p>Book_list:</p>
  
  <pre><code>NO | MAIN_BOOK_NO | MAIN_BOOK_NAME | BOOK_SUP_NO | AUTHOR_NO
  1  |    12        |    xyz         |   5         |   2
  2  |    22        |    abc         |   7         |   4
  </code></pre>
  
  <p>Authors:</p>
  
  <pre><code>NO | AUTHOR_NO | AUTHOR_NAME
   1 |  2        | Alex
   2 |  3        | Leonard
   3 |  4        | Benjamin
  </code></pre>
  
  <p>Supplementary:</p>
  
  <pre><code>NO | BOOK_NO | BOOK_NAME 
  1  |   5     |   ABC
  2  |   5     |   XYZ
  3  |   7     |   LMN
  4  |   7     |   DEF
  5  |   7     |   NEW
  </code></pre>
  
  <p>The output should be like</p>
  
  <pre><code>         NAME
  12,xyz,Alex,-5,ABC,-5,XYZ
  22,abc,Benjamin,-7,LMN,-7,DEF,-7,NEW
  </code></pre>
  
  <p>Similarly for the entire data in the table</p>