The query looks all right to me, though I don't understand the bit about the
Union query. Also, I don't know what you are doing in the qryRatioSorted
query, but if you're just sorting it, you might want to run it directly
against the table since this query is also sorting it.
--
--Roger Carlson
Access Database Samples:
www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
I tried using your example and modified to:
select I1.*
from [qry Ratio Sorted] as I1
where (((I1.[Ratio]) in (select top 5 [Ratio] from [qry Ratio Sorted] I2
where I1.[Dealer_Code] = I2.[Dealer_Code] order by I2.[Ratio] desc)))
order by I1.Dealer_Code,I1.[Ratio] DESC;
I created this in a sql union query. I tried running the query and after a
few minutes access fell over with an error. Before I try again can you
confirm if this Is right?
Thanks
Sue
:
Thanks Roger, will look at your example. For reference my SQL is
SELECT [qry Ratio].*
FROM [qry Ratio]
ORDER BY [qry Ratio].DEALER_CODE, [qry Ratio].Ratio DESC;
Currently there are 73879 records. I want just the first five records
of
each dealer code, totalling approx 1000 records.
P.S. Sorry if this posts twice the first time I think it failed?
--
Thanks
Sue
:
You need to use a correlated subquery. If you had given your SQL for
the
query, I might have been able to show you something. As is, the best
bet is
to look at a sample and generalize from there.
Suppose I have an Invoices table with AccountNum, OrderNum, and
TotalPrice.
Suppose further, I want to show the Top 3 orders (by TotalPrice) for
each
Account. I could do this:
SELECT I1.Account, I1.OrderNum, I1.[Total Price]
FROM Invoices AS I1
WHERE (((I1.[Total Price]) In (SELECT TOP 3 [Total Price] FROM
Invoices I2
WHERE I1.[account] = I2.[account] ORDER BY I2.[total price]
desc)))
ORDER BY I1.Account, I1.[Total Price] DESC;
On my website (
www.rogersaccesslibrary.com), is a small Access
database
sample called "TopQuery.mdb" which discusses a number of issues with
Top
queries, including this. Look at example 4.
--
--Roger Carlson
Access Database Samples:
www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
Hi all
I have a query which holds data for dealerships, I have the query
sorted
in
a specific order and what I need is to be able to take the first
five
records
of each dealer and mail merge results in word. How can I obtain just
the
first five records for each dealer maintaining my sort order? I
can't
write
to a table using an autonumber Rank field as I would need the Rank
to
start
at 1 again each time the dealer number changed.
Any help asap would be most appreciated thanks.
Sue