values of each product and your suppliers?

  • Thread starter Thread starter Frank Dulk
  • Start date Start date
F

Frank Dulk

How do I do in a query to catch the smallest values of each product and your
suppliers?

I get to recover the product the smallest value it just lacks the suppliers,
because when I increase the suppliers it duplicates the records
 
Frank, I assume you get some products from multiple suppliers.
You therefore have 3 tables, something like this:

tblProduct
ProductID AutoNumber primary key
ProductName...

tblSupplier:
SupplierID AutoNumber primary key
SupplierName...

tblProductSupplier:
ProductID Number matches tblProduct.ProductID
SupplierID Number matches tblSupplier.SupplierID
PriceEach Currency Cost of this product from this supplier.

Now you want to know the lowest price from each Product. You could use a
subquery to find either the supplier or the price, but not both at once.
This query shows how to get the cheapest supplier for the product:

SELECT tblProduct.*,
( SELECT TOP 1 SupplierID
FROM tblProductSupplier
WHERE tblProductSupplier.ProductID = tblProduct.ProductID
ORDER BY PriceEach, tblProductSupplier.SupplierID )
AS CheapestSupplier
FROM tblProduct;

For more help, see:
Getting a related field from a GroupBy (total) query
at:
http://www.mvps.org/access/queries/qry0020.htm
Michel Walsh explains 4 ways to get the result.
 
Thank you.
A detail, I am inspired by you.


Allen Browne said:
Frank, I assume you get some products from multiple suppliers.
You therefore have 3 tables, something like this:

tblProduct
ProductID AutoNumber primary key
ProductName...

tblSupplier:
SupplierID AutoNumber primary key
SupplierName...

tblProductSupplier:
ProductID Number matches tblProduct.ProductID
SupplierID Number matches tblSupplier.SupplierID
PriceEach Currency Cost of this product from this supplier.

Now you want to know the lowest price from each Product. You could use a
subquery to find either the supplier or the price, but not both at once.
This query shows how to get the cheapest supplier for the product:

SELECT tblProduct.*,
( SELECT TOP 1 SupplierID
FROM tblProductSupplier
WHERE tblProductSupplier.ProductID = tblProduct.ProductID
ORDER BY PriceEach, tblProductSupplier.SupplierID )
AS CheapestSupplier
FROM tblProduct;

For more help, see:
Getting a related field from a GroupBy (total) query
at:
http://www.mvps.org/access/queries/qry0020.htm
Michel Walsh explains 4 ways to get the result.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

query too slow 1
Update query help 2
Canon IP 6600D Photo Printer 2
query very slow 5
Pulling Active Suppliers by year 4
Simple query?? 4
Finding a count of duplicates 4
Flag Dupplicate Records 1

Back
Top