Top 10 in a query

Leesha
BronzeLounger
Posts: 1488
Joined: 05 Feb 2010, 22:25

Top 10 in a query

Post by Leesha »

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

User avatar
HansV
Administrator
Posts: 78488
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Top 10 in a query

Post by HansV »

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
Best wishes,
Hans