How to use a condition on listagg on Oracle query
<p>I have 3 tables: table_A, table_B and table_C. Table_A has a Primary key and is referred by a foreign key from table_B. Table_C has a primary key referred by a foreign key from table_B. The design is like this:</p>

<pre><code>T̲a̲b̲l̲e̲_̲A̲
ID_A
TextData

T̲a̲b̲l̲e̲_̲B̲:
ID_B
ID_A
ID_C

T̲a̲b̲l̲e̲ ̲C̲:
ID_C
TextData
</code></pre>

<p>the query:</p>

<pre><code>select a.id_a,
       a.textdata,
       listagg(c.textdata, ', ') within group (order by c.id_c) data_c
from   table_a a
       inner join table_b b on (a.id_a = b.id_a)
       inner join table_c c on (b.id_c = c.id_c)
where c.textdata like :data
group by a.id_a, a.textdata;
</code></pre>

<p>I just get data from one table of c.textdata, not from listagg. If I try to using this query:</p>

<pre><code>select a.id_a,
       a.textdata,
       listagg(c.textdata, ', ') within group (order by c.id_c) data_c
from   table_a a
       inner join table_b b on (a.id_a = b.id_a)
       inner join table_c c on (b.id_c = c.id_c)
where listagg(c.textdata, ', ') like :data
group by a.id_a, a.textdata;
</code></pre>

<p>I get an error like : <strong>group function is not allowed here</strong></p>

<p>How to give a condition on listagg parameter, because I need the data from listagg?</p>