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... 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! 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
Archived
This topic is now archived and is closed to further replies.