stefd
03-29-2001, 10:19 AM
Hi, I need some help to build an SQL query (I am pretty new to this stuff...)
I have 2 tables, one with products, and one with categories. Each of the products is classified in one of the categories.
So, the tables would look like this:
Categories table
================
catId
catName
Products table
==============
prodId
prodName
catId (id of category this product falls in)
What I want is to know how many products are in each category. The result I'm looking for would look like:
catId | number of products
==========================
1 | 10
2 | 20
3 | 0
4 | 0
5 | 4
and so on...
I've tried, but I can't come up with the correct SELECT query to generate the desired result.
Is it possible to build such a query, or do I have to code a loop to go through each category explicitly?
Thanks for your help!
I have 2 tables, one with products, and one with categories. Each of the products is classified in one of the categories.
So, the tables would look like this:
Categories table
================
catId
catName
Products table
==============
prodId
prodName
catId (id of category this product falls in)
What I want is to know how many products are in each category. The result I'm looking for would look like:
catId | number of products
==========================
1 | 10
2 | 20
3 | 0
4 | 0
5 | 4
and so on...
I've tried, but I can't come up with the correct SELECT query to generate the desired result.
Is it possible to build such a query, or do I have to code a loop to go through each category explicitly?
Thanks for your help!