473,557 Members | 2,746 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sql sort records by count

229 New Member
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
2 1157
Rabbit
12,516 Recognized Expert Moderator MVP
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 New Member
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
2643
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", "last_name", and "city" are columns in the table. The requirement is to ALSO sort by department NAME. Problem is, I can't do that in the "person"...
3
2552
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? Thanks for help Lad
6
3812
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 display catgories names from first table and then diffren catagories total records from second table, like this
12
18994
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, frmBrowseNegsSubform. I would like to perform an ascending or descending sort on any of the 7 columns shown in datasheet view in the subform control. I've...
22
17848
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
2713
by: srikanth | last post by:
please give me any helpful logics for the subject
3
5932
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 then "cancelled" Then within those cases it should sort by priority. I know how to sort ascending and descending on forms.
3
6112
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 requesting the work and it is assigned a number using the autonumber feature and the date is also put in automatically, then it is entered in the...
20
4467
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 has this name: "CityMajor" 3. Imagine that we wish to have a query sort the items in this column, but with one exception: One of the records should...
0
8061
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6180
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5454
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5172
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3599
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3577
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2044
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1161
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
867
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.