Hello, all, I've got a query that is giving me fits. I'm trying to bring some code that my boss recently wrote into the 21st century. One section that he wrote, he is using three queries to get base information, looping through one of the queries and running a query within that loop. I hate this. Every time I see code that runs a query within a loop, it makes my teeth itch. So, I'm trying to run a single query using LEFT OUTER JOIN. I've got it working, but for one thing. I am trying to get our Oracle db to aggregate some data into a string using LISTAGG(), and that is causing this query to take 14 seconds to get the data (the way my boss wrote the code, it's almost instant.) Of the two tables involved, one has ~2000 records, the other ~4000, and the query is retrieving 23. If I take out the LISTAGG() portion, the query is almost instant. I was hoping to get the db to do more of the heavy lifting. Is there anything faster than LISTAGG() for aggregating data into a string in Oracle 12c? SELECT m1.uuid, m1.title, m1.description, (SELECT listagg(title,', ') within group (order by null) csv FROM main WHERE uuid in (SELECT role_uuid FROM assoc WHERE task_uuid = m1.uuid)) related_titles FROM main m1 WHERE m1.uuid in (SELECT a1.task_uuid FROM assoc a1 WHERE a1.role_uuid = '{uuid}' AND task_uuid is not null) ORDER BY m1.title V/r, ^ _ ^
... View more