I have three tables that I need to retrieve info from: Products, ProductOptions, and OptionChoices. As of now this is the SQL I am using to get said information
select P.ProductId,P.Name,P.StoreId,PO.OptionId,OC.ChoiceName from Products P
inner join ProductOptions PO on P.ProductId=PO.ProductID
inner join OptionChoices OC on PO.OptionId=OC.OptionId
where P.ProductId=23317
which outputs this:
ProductId Name StoreID OptionId ChoiceName
23317 Admiral Ackbar Cereal 629 795 fish
23317 Admiral Ackbar Cereal 629 795 shrimp
23317 Admiral Ackbar Cereal 629 795 traps
23317 Admiral Ackbar Cereal 629 797 box
23317 Admiral Ackbar Cereal 629 797 casket
What would make my life a lot easier is if I could add one more column that would give me the total number of Choices for Each OptionId. So the first row would read:
ProductId Name StoreID OptionId ChoiceName Count
23317 Admiral Ackbar Cereal 629 795 fish 3
Because there are 3 Choices with 795 as their OptionIds. I've tried using different combinations of group by and count, but have had no luck. Anyone have any ideas to point me in the right direction?
Edit: I am using SQL Server