Usaría listagg()
en una subconsulta:
select t1.*, xmlagg
from table1 t1 join
(select name2, listagg(mother_name, ',') within group (order by mother_name) as xmlagg
from table2 t2
group by name2
) t2
on t1.name1 = t2.name2;
EDITAR:
La consulta anterior realiza la agregación antes de la unión, por lo que puede usar t1.*
. También puede hacerlo después de unirse:
select t1.name, listagg(mother_name, ',') within group (order by mother_name)
from table1 t1 join
table2 t2
on t1.name1 = t2.name2
group by t1.name;
Este formulario hace que sea más difícil agregar columnas adicionales al select
, pero puede agregar por lo que quiera.