Hi,
I have a query with the following sql:
SELECT TOP 10 qryCOSDXReportInitial.DXCatagory, Sum(qryCOSDXReportInitial.[1]) AS 1
FROM qryCOSDXReportInitial
GROUP BY qryCOSDXReportInitial.DXCatagory;
It should return the top 10 [DXCatagory] with the highest numbers in [1]. Instead its returning the top ten [DXCatagory] based on alphabetical order. I tried putting Sum(qryCOSDXReportInitial.[1]) AS 1 i nthe first column but that didn't change the results. What am I missing?
Thanks,
Leesha
Top 10 in a query
-
- Administrator
- Posts: 78488
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Top 10 in a query
You have to sort the query by the field on which you want to obtain the top 10:
SELECT TOP 10 qryCOSDXReportInitial.DXCatagory, Sum(qryCOSDXReportInitial.[1]) AS 1
FROM qryCOSDXReportInitial
GROUP BY qryCOSDXReportInitial.DXCatagory
ORDER BY Sum(qryCOSDXReportInitial.[1]) DESC
SELECT TOP 10 qryCOSDXReportInitial.DXCatagory, Sum(qryCOSDXReportInitial.[1]) AS 1
FROM qryCOSDXReportInitial
GROUP BY qryCOSDXReportInitial.DXCatagory
ORDER BY Sum(qryCOSDXReportInitial.[1]) DESC
Best wishes,
Hans
Hans