bubbasheeko Posted February 9, 2009 Share Posted February 9, 2009 I am not sure how to do this.... I have a database: Customer Name Item Number Quantity_Purchased Amount_Due What I want to do is see one of each Item Number. So...if more than one item is purchased by more than one person, I want to see an 'individual' list of items. I need to do this with one query. Example output: Item Number 00022 00233 35221 Now 00022 has 23 purchased - so it will have at least 23 individual records...I only want to see the item in the list once. I hope this makes sense... Quote Link to comment https://forums.phpfreaks.com/topic/144514-select-one-of-each-item-query/ Share on other sites More sharing options...
jon15n Posted February 9, 2009 Share Posted February 9, 2009 It makes perfect sense. It is an easy SELECT query. SELECT item_number, count(*) as Items_purchased FROM table GROUP BY item_number Note that if you want to include the sum of quantity purchased instead of just a count for each order, you would want to use this query: SELECT item_number, sum(Quantity_Purchased) as Quantity_purchased FROM table GROUP BY item_number Good luck! Quote Link to comment https://forums.phpfreaks.com/topic/144514-select-one-of-each-item-query/#findComment-758454 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.