473,809 Members | 2,740 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Catego ryID,
Category.Catego ry,
Category.Sortin g
From
Category
Order By
Category.Sortin g Desc
Items:
Select Count(Listings. CategoryID)
From
Listings
Group By
Listings.Catego ryID
I've tried the following but can't get it to work:
Select
Category.Catego ryID,
Category.Catego ry,
Category.Sortin g,
(Select Count(Listings. CategoryID)
From
Listings WHERE Listings.Catego ryID = Category.Catego ryID) AS cnt
From

Category
Order By
Category.Sortin g Desc

Apr 10 '06 #1
1 4603
Select
Category.Catego ryID,
Category.Catego ry,
Category.Sortin g,
Count(Listings. CategoryID) as cnt
From Category, Listing

WHERE Listings.Catego ryID = Category.Catego ryID)
group by
Category.Catego ryID,
Category.Catego ry,
Category.Sortin g
Order By
Category.Sortin g 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
4414
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. So a row looks like this: 'unique id | 4' What i want is to do a count how much rows belong to a certain category.
5
4209
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 for all the images and a field to specify what category the images are assigned to. I am trying to write a simple Select query that will return a list of Categories from my Category table, and in the second colum a count of the number of images...
1
1488
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 and the number of items in that category. I could do this in two sql statements, is it possible to do it in one? Thanks~
3
5103
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 orders quarterly, and at the same time how many different item numbers used in each quarter.
2
1338
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 example of what I am looking for can be found at http://www.411asp.net/, looking like the following: Web Applications (272) Content Managers, Forum, E-Commerce, ...
10
1842
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 specific set of numbers for each vendor listed in it. i.e. Expence Catigory is Office Supplies... all vendors for that catigory are listed between 22401 and 22499. Is there a way to have it auto number so Office supplies would start at
7
3539
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 number of items in each Cats: Select Category.CategoryID, Category.Category, Category.Sorting
3
2554
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 how to do this. Here is the structure of the 2 tables:
2
1469
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 en_print_200802.xml which is called form a seperate .xml volissue.xml beside each name i want to display the # of items in each category. <?xml version="1.0" encoding="utf-8"?> <vol_issue vol_issue_id="200802"> ...
2
11262
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 : 1 of 15. Is there any suggesting how to get total page number. Public int y = 0; Public int LineCount = 0; int yPosition = 50; e.Graphics.DrawString("Summary of Image Data", drawHeaderFont, drawBrush, 50, yPosition,...
0
9602
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10376
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10383
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10120
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9200
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6881
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5688
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
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

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.