Hi - Just wanted to follow up to say that using the format John suggested
accomplished the task, thanks again John.
The one hiccup, and I guess a followup question, is just that on a table of
about 84,000 records the query I wrote took a pretty long time to run (>a
couple of minutes, I got distracted after that), and the next step for me is
to do the same kind of query but involving several joins including a big
sales history table (1.5 million records) and at least three calculated
fields.
So the followup question would be are there any tricks for maybe lightening
the load so I don't have to run the query overnight!?
Here's the actual SQL I used for the first query (with 'Bisac_corr' being
the field 'type' stood in for in the simplified example, and 'Price_Latest'
being the field examined for top 20 values.)
SELECT T1.ISBN13, T1.TitleShort, T1.Author, T1.DatePub, T1.SAC,
T1.Bisac_Corr, T1.Publisher_Corr, T1.Price_Latest
FROM tblEntityTitles AS T1
WHERE (((T1.Price_Latest) In (SELECT Top 20 Price_Latest FROM
tblEntityTitles as T2 WHERE (T2.Bisac_Corr = T1.Bisac_Corr) ORDER BY
Price_Latest DESC)))
ORDER BY T1.Bisac_Corr;
John Spencer MVP said:
Try a correlated subquery in the where clause
SELECT SomeTable.*
FROM SomeTable
WHERE Book_Sales in
(SELECT Top 20 Book_Sales
FROM SomeTable as S
WHERE S.Book_Type = SomeTable.Book_Type
ORDER BY Book_Sales DESC)
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
I'm trying to create a query to return the top 20 of each of a 'type' of
record in a table.
So say the table has columns:
Book_Type {Good, Bad, Indifferent}
Book_Title
Book_Sales [in $]
What I'm trying to do is get the top 20 sellers in each of the three
Book_Type values.
I'm thinking some kind of subquery...?
Thanks,
Jaek