473,325 Members | 2,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Sql sort records by count

229 100+
Hi, I wonder if anyone can help with this query.

I have a table with categories as follows

profileid, categories
1224 abstract
234 illustration
2345 abstract
4 drawing
56 sculpture



This code works and creates me a list of categories.

Expand|Select|Wrap|Line Numbers
  1.            SQLQuery = "SELECT DISTINCT tblA.categories" _
  2.  & " FROM tblA" _
  3. & " where tblA.profileid<>'' " _
  4. & " ORDER BY tblA.categories asc"
  5.  


what I need the query to do now is to include only the 10 most used categories.
Any help would be great.
Thanks
Richard
Feb 6 '14 #1

✓ answered by Rabbit

Use a count, do a group by on the categories, sort by the count descending, use the top predicate to get only the first 10.

2 1148
Rabbit
12,516 Expert Mod 8TB
Use a count, do a group by on the categories, sort by the count descending, use the top predicate to get only the first 10.
Feb 6 '14 #2
fran7
229 100+
Thanks, this worked

Expand|Select|Wrap|Line Numbers
  1. select top 15 tblA.categories from tblA group by categories 
  2. order by count(categories) desc
All the best
Richard
Feb 6 '14 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Phil Powell | last post by:
Very simplistic but I am utterly STUMPED at this one. I have a db table "person" that I can sort by title, first_name, last_name, or city with no problems at all because "title", "first_name",...
3
by: Lad | last post by:
What is the best( easiest)way how to sort a file? I have a file where each record consists of 3 fields( 3 words) and I would like to sort records by the first field( word)in each record. Any idea?...
6
by: asad | last post by:
Hi, i have some problem in showing data. I have two tables First table(containing Hosting categories) Second table(Containg catagories data lik url,keyword,description.....etc) I want to...
12
by: MLH | last post by:
I have created two forms: frmBrowseNegsMainform and frmBrowseNegsSubform. I put a subform control on the first of these. The SourceObject property for the subform control is, of course,...
22
by: Nhmiller | last post by:
Is there a way to do this? Thanks. Neil Cat Paintings At Carol Wilson Gallery http://www.carolwilsongallery.com
3
by: srikanth | last post by:
please give me any helpful logics for the subject
3
by: usaccess | last post by:
Hi, I have a form/subform. There is a priority field and then a case status field. I want to display records so that it sorts by case status as "actives" then "on holds" then "completes" and...
3
by: sail87 | last post by:
I inherited an Access 2003 database and need to change the way a form is sorted. It seems to work like this. There is a table containing work records of work requests. The user fills out a form...
20
nicebasic
by: nicebasic | last post by:
I would like to have a query for ASP Classic to be applied on an Access database. 1. Imagine that we have a table with the name of "Country". 2. Imagine that we have a column in "Country" that...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.