473,324 Members | 2,541 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,324 software developers and data experts.

Count Number of Items in each Category

I'm trying to list my categories and how many items are in each
category. I'm not much on sub queries. How can I combine these two
items. I'd like to display the category and the corresponding number of

items in each

Cats:
Select
Category.CategoryID,
Category.Category,
Category.Sorting
From
Category
Order By
Category.Sorting Desc
Items:
Select Count(Listings.CategoryID)
From
Listings
Group By
Listings.CategoryID
I've tried the following but can't get it to work:
Select
Category.CategoryID,
Category.Category,
Category.Sorting,
(Select Count(Listings.CategoryID)
From
Listings WHERE Listings.CategoryID = Category.CategoryID) AS cnt
From

Category
Order By
Category.Sorting Desc

Apr 10 '06 #1
1 4554
Select
Category.CategoryID,
Category.Category,
Category.Sorting,
Count(Listings.CategoryID) as cnt
From Category, Listing

WHERE Listings.CategoryID = Category.CategoryID)
group by
Category.CategoryID,
Category.Category,
Category.Sorting
Order By
Category.Sorting Desc

If you are going to continue doing SQL - a good reference book would be
in order. Also - the term (in this case) that you would use for Google
would be Joins, Cross Joins

Apr 10 '06 #2

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

Similar topics

6
by: knoak | last post by:
Hi there, I have a small question: I have a table with lots of rows in it. Of course all have a different id, but each can be assigned to a certain category. Categories correspond with 1 - 10....
5
by: Mark | last post by:
Hi, I have a Access database with two tables; a category table and an images table. In the Category table I have a field for Index number and a field for Categories. The images table has a field...
1
by: mfyahya | last post by:
Hi, I have a `category` table with columns cat_id and cat_name. And another `items` table with columns item_id, item_name and cat_id. I want a query which will select display each category name...
3
by: Anne | last post by:
Hi I have got a table with some sales transactions. It has got 3 fields 1) Ordernumber 2) Item number 3) Shippingdate Now I want to make ONE (not two) query that shows how many different...
2
by: Chad A. Beckner | last post by:
Hey all, Does anyone have an example of where I can find ASP .NET code for creating categories followed by the count (number of items in the category) page? I can't find an example! :-( and...
10
by: Marina | last post by:
Can anyone tell me if there is a way to auto number by category? I have 2 tables, ExpenseCategories and Vendors. Each there are many vendors to each expense category, but each category has a...
7
by: Barkster | last post by:
I'm trying to list my categories and how many items are in each category. I'm not much on sub queries. How can I combine these two items. I'd like to display the category and the corresponding...
3
by: acorn71 | last post by:
Hello, I need to write a SELECT statement that will display the most popular categories. This means I need a 'category count' for each of the messages in the messages table, and I don't know...
2
by: googletired | last post by:
Ok, I need to be able to count the # of items for each category and have it display. So say i have a left menu that displays that category name for cat in the current issue.xml for instance...
2
by: winzone | last post by:
Hi All, Now i use the following code to print the data in C# 2005 application. But i face the problem is total page number at the begining of first page. They want to get page number like : Page :...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.