472,328 Members | 1,730 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,328 software developers and data experts.

Sort by a second field in a SELECT TOP query

The following query will give me the top ten states with the most callers.

SELECT TOP 10 Count(Callers.CallerID) AS CountOfCallerID, Callers.State
FROM Callers
GROUP BY Callers.State
ORDER BY Count(Callers.CallerID) DESC;

How can I return the same result set, the top ten states, but sort the
result set by state.

Thanks for any help.
Nov 13 '05 #1
5 6550
Simplest way is to use this query as the datasoure for another one that
sorts by State.

Larry Linson
Microsoft Access MVP

"Terri" <Te***@spamaway.com> wrote in message
news:ch**********@reader2.nmix.net...
The following query will give me the top ten states with the most callers.

SELECT TOP 10 Count(Callers.CallerID) AS CountOfCallerID, Callers.State
FROM Callers
GROUP BY Callers.State
ORDER BY Count(Callers.CallerID) DESC;

How can I return the same result set, the top ten states, but sort the
result set by state.

Thanks for any help.

Nov 13 '05 #2
Fair enough. Any way with just one query. I'm building SELECT statements
dynamically in a reporting application
Thanks
"Larry Linson" <bo*****@localhost.not> wrote in message
news:76PZc.5371$_%3.4643@trnddc06...
Simplest way is to use this query as the datasoure for another one that
sorts by State.

Larry Linson
Microsoft Access MVP

"Terri" <Te***@spamaway.com> wrote in message
news:ch**********@reader2.nmix.net...
The following query will give me the top ten states with the most callers.
SELECT TOP 10 Count(Callers.CallerID) AS CountOfCallerID, Callers.State
FROM Callers
GROUP BY Callers.State
ORDER BY Count(Callers.CallerID) DESC;

How can I return the same result set, the top ten states, but sort the
result set by state.

Thanks for any help.


Nov 13 '05 #3
Terri wrote:
Fair enough. Any way with just one query. I'm building SELECT statements
dynamically in a reporting application
Thanks
"Larry Linson" <bo*****@localhost.not> wrote in message
news:76PZc.5371$_%3.4643@trnddc06...
Simplest way is to use this query as the datasoure for another one that
sorts by State.

Larry Linson
Microsoft Access MVP

"Terri" <Te***@spamaway.com> wrote in message
news:ch**********@reader2.nmix.net...
The following query will give me the top ten states with the most
callers.
SELECT TOP 10 Count(Callers.CallerID) AS CountOfCallerID, Callers.State
FROM Callers
GROUP BY Callers.State
ORDER BY Count(Callers.CallerID) DESC;

How can I return the same result set, the top ten states, but sort the
result set by state.

Thanks for any help.


Usually you sort by using the Sorting/Grouping dialog in a report. You
can also use the OrderBy and OrderByOn properties of a report to set the
sort order.

IOW, remove the sort order in the query (since sorting is irrelevent as
a report's recordsource).

If your problem is not in regards to a report, ignore this post.
Nov 13 '05 #4
Salad's reply is correct, except in one respect: the sort order of the data
in the RecordSource is ignored in a report, and only the sorting and
grouping in the Report's Sorting and Grouping property used to control the
display.

However, in your case, the ORDER BY is necessary to choose the proper TOP
values.

Larry Linson
Microsoft Access MVP

"Salad" <oi*@vinegar.com> wrote in message
news:AF***************@newsread3.news.pas.earthlin k.net...
Terri wrote:
Fair enough. Any way with just one query. I'm building SELECT statements
dynamically in a reporting application
Thanks
"Larry Linson" <bo*****@localhost.not> wrote in message
news:76PZc.5371$_%3.4643@trnddc06...
Simplest way is to use this query as the datasoure for another one that
sorts by State.

Larry Linson
Microsoft Access MVP

"Terri" <Te***@spamaway.com> wrote in message
news:ch**********@reader2.nmix.net...

The following query will give me the top ten states with the most


callers.
SELECT TOP 10 Count(Callers.CallerID) AS CountOfCallerID, Callers.State
FROM Callers
GROUP BY Callers.State
ORDER BY Count(Callers.CallerID) DESC;

How can I return the same result set, the top ten states, but sort the
result set by state.

Thanks for any help.


Usually you sort by using the Sorting/Grouping dialog in a report. You
can also use the OrderBy and OrderByOn properties of a report to set the
sort order.

IOW, remove the sort order in the query (since sorting is irrelevent as
a report's recordsource).

If your problem is not in regards to a report, ignore this post.

Nov 13 '05 #5
"Terri" <Te***@spamaway.com> wrote in message news:<ch**********@reader2.nmix.net>...
The following query will give me the top ten states with the most callers.

SELECT TOP 10 Count(Callers.CallerID) AS CountOfCallerID, Callers.State
FROM Callers
GROUP BY Callers.State
ORDER BY Count(Callers.CallerID) DESC;

How can I return the same result set, the top ten states, but sort the
result set by state.


Use this query as the source for another query:

SELECT *
FROM (SELECT TOP 10 Count(Callers.CallerID) AS CountOfCallerID, Callers.State
FROM Callers
GROUP BY Callers.State
ORDER BY Count(Callers.CallerID) DESC)
ORDER BY Callers.State ;
Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: tom r. | last post by:
I have a table with records in a desired sort order (I appended them to the table in the order I wanted). It would look something like this: ...
11
by: James P. | last post by:
Hello, I have a report with the Priority field is used as sort order and grouping. The problem is the data in this Priority field if sorted in...
3
by: A. Respecte | last post by:
I have a list of IP addresses, amongst other fields in a db that I need to sort, however, I am having difficulties accomplishing that, and any help...
6
by: Les Juby | last post by:
I need to extract records from a database subject to conditions and only thereafter give the users the choice of which fields to sort the results...
7
by: Arnold | last post by:
Greetings Gurus, In a mainform's header, I have a combobox named comboStudents. The rowsource for this combobox is: SELECT -999 As StudentID,...
3
by: beconrad | last post by:
Hi all, I am not sure if what I want to do is possible, and if it is I have not been able to figure out how to do it. This is what I would like:...
6
by: Kc-Mass | last post by:
In a standard Ascii table a dash or hyphen is decimal 45. A period or dot is decimal 46. If I sort a table or recordset of mixed character string...
5
by: muskie | last post by:
I've looked through as many posts about this as possible, but all end with no resolution. I simply need records from a table in random order, and...
4
by: zion4ever | last post by:
Hello good people, Please bear with me as this is my first post and I am relative new to ASP. I do have VB6 experience. I have a form which...
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.