Query group by and display other columns

VDJ

New member
Local time
Today, 10:47
Joined
Sep 2, 2013
Messages
6
Hi all,

I have a table with 4 columns :
Product Price Quantity Supplier

Product1 5 240 A
Product1 7 19 B
Product1 6 12 C
Product2 96 0 A
Product2 98 23 B
Product2 99 44 C

There are 3 suppliers for the products (name of the suppliers are A, B and C).
I want to make a query with the following result :
Product1 5 240 A
Product2 98 23 B

In other words :
Showing a grouped list (grouped by products), with the lowest price of the supplier who has stock (quantity >0).
I can make a list of grouped products with the lowest price, but it's not possible for me to show the stock and the supplier that's related with it.

Thanks in advance.

Johan
 
Not tested but try:

Code:
SELECT * 
FROM myTable 
WHERE Price=(SELECT Min(Price) FROM myTable as tmp WHERE Product=myTable.Product AND Quantity<>0)

You'll need to change names to suit
 
Thank you very much, it works from the first time !

I appreciate your help very much.

Johan.
 

Users who are viewing this thread

Back
Top Bottom