Forum Moderators: open
table: OrderItem
pertinent columns: idItem, sTitle, iQuantity, idOrder
i'm trying to make a SQL statement that will loop through the table, and obtain the most popular items sold. the problem i have is that there are duplicate sTitles (due to the fact that different orders can have the same item).
i.e.
idItem - sTitle - iQuantity - idOrder
1 - Blue Widget - 5 - 100
3 - Red Widget - 1 - 23
1 - Blue Widget - 3 - 140
2 - Green Widget - 10 - 132
i need to show that Green Widget is the most popular item (with 10 sold), Blue Widget ranks 2nd (with 8 sold), and Red ranks 3rd (with 1 sold). can anyone help? i think it might be easy, but i can't get the results i'm looking for.
-Matt
This will give you how many items are on the most orders (which could also be a slightly different measure of "most popular"):
Select sTitle, Count(iQuantity) AS Qty From OrderItem Group By sTitle Order By Qty DESC