Top N query never finishes processing.

PaulCL

New Member
Joined
Jul 9, 2014
Messages
43
I have a table(Orders) with 5 million records that also contains 250 unique groups(Markets). I am trying to apply a Top N query to retrieve the top 3 records(FirmNames), based on TotalVolume, from each unique group. My current query never finishes running. Is there a more efficient way to retrieve these top 3 records? Thanks

SELECT Orders.Market, Orders.TotalVolume, Orders.FirmName INTO [Top 3 Luxury Market Final]
FROM Orders
WHERE (((Orders.TotalVolume) In (SELECT TOP 3 TotalVolume
FROM Orders AS Dupe
WHERE Dupe.Market = Orders.Market
ORDER BY Dupe.TotalVolume DESC, Dupe.FirmName DESC)))
ORDER BY Orders.Market, Orders.TotalVolume DESC , Orders.FirmName;
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
I think it will be faster if you try to simplify the process in more than one step, considering the large volume of data you are dealing with. The IN Clause in your Query itself is a delaying factor.

Create a temporary table by summarizing on Company & Order-wise total value. Creating this table itself will eliminate detailed items under each Order and reduce the table size.

Try running your Query on this temporary table or create SELECT Query with TOP N setting to get the result.

If you need this to be done frequently then sequence the process in a Macro and run from a command button click.
 
Last edited:
Upvote 0
I think it will be faster if you try to simplify the process in more than one step, considering the large volume of data you are dealing with. The IN Clause in your Query itself is a delaying factor.

Create a temporary table by summarizing on Company & Order-wise total value. Creating this table itself will eliminate detailed items under each Order and reduce the table size.

Try running your Query on this temporary table or create SELECT Query with TOP N setting to get the result.

If you need this to be done frequently then sequence the process in a Macro and run from a command button click.

Thanks for the help.
 
Upvote 0

Forum statistics

Threads
1,221,845
Messages
6,162,350
Members
451,760
Latest member
samue Thon Ajaladin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top