Jump to content

Select one of each item - query


bubbasheeko

Recommended Posts

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

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.