Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count on composite keys

Status
Not open for further replies.

rigobertocorrales

Technical User
Jan 20, 2009
2
CR
Hi:
I have the following table containing ingredients of products:

IngredientsInProducts(ProductId, Ingredient_Category, Ingredient_Id) The 3 attributes are PK

How could I count all the ingredients (Ingredient_Category and Ingredient_Id) that appear on the table?. Eg
-----------------------------------------------
Ingredient_Category --- Ingredient_Id --- Count
01 001 10
02 099 3
...
-----------------------------------------------

Thanks

 

Did you try using the COUNT() aggregate function?
[3eyes]


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
This seems like a very simple aggregate query:
SELECT Ingredient_Category, Ingredient_Id, COUNT(*)
FROM IngredientsInProducts
GROUP BY Ingredient_Category, Ingredient_Id

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
You were right dudes:

Solved with the code of PHV. The trick was in Count(*)

Thanks

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top