Re: Better way to write this query?
Posted by: Peter Brawley
Date: June 01, 2021 02:21PM

The forum software understands BBCode code tags. I added a couple of pairs to your post.

Your correlated subqueries in the Select list are bound to be slow since they inefficiently require a join data-read per row, so they need to be moved to the FROM clause.

I take it you need to extract 4 ordered data subsets per some key value; there are optimisable ways to do that sort of thing, see articles titled ...

Within-group quotas (Top N per group)
Top ten

... at https://www.artfulsoftware.com/infotree/queries.php ... such methods work fine in From clause subqueries and won't require Select list correlated subqueries.

Your partial sketch of the requirement suggests your query may also need some rows-to-columns logic, see that and "Pivot tables" at the above link.

Unfortunately I don't follow your explanation of how the query is to derive the result row ...
Account # Date Submitted Placement # First Placement First Placement Location
123456     05-21-2021     4           03-24-2021            My Company

... so for more help, I'll need you to you post the Show Create Table results for relevant tables, and just enough Inserts to support a meaningful test query.

Options: ReplyQuote


Subject
Written By
Posted
Re: Better way to write this query?
June 01, 2021 02:21PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.