whittinga2
asked on
Maximum Record Selection
I have a table:
Product
This table is linked to another table:
Product Price
This table contains:
Price Date
Price
I need to be able to select the latest price for a product.
Product
This table is linked to another table:
Product Price
This table contains:
Price Date
Price
I need to be able to select the latest price for a product.
The query will be something like
SELECT Product.ID, Product.Description, ...
(SELECT Price.Price FROM Price WHERE Price.ProductID = Product.ID AND Price.PriceDate = Maximum(Price.PriceDate)
FROM Product
mlmcc
SELECT Product.ID, Product.Description, ...
(SELECT Price.Price FROM Price WHERE Price.ProductID = Product.ID AND Price.PriceDate = Maximum(Price.PriceDate)
FROM Product
mlmcc
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
FWIW, you _could_ find the most recent price in a report, but it would probably be much more efficient to do it in the db query, as mlmcc suggested. It would depend a lot on your data and the report, and what you wanted to do with that price (just display it, or use it in calculations).
James
James
ASKER
Cheers fellas. I will give it a go and get back to you.
Sorry for the delay.
Sorry for the delay.
ASKER
Any idea why I've been given a syntax error?
SELECT *
(SELECT * FROM pricehistory WHERE pricehistory.productid = productdetails.productid AND pricehistory.priceeffectiv efromdate =
(SELECT Maximum(pricehistory.price effectivef romdate) FROM pricehistory WHERE pricehistory.productid = productdetails.productid))
FROM productdetails
SELECT *
(SELECT * FROM pricehistory WHERE pricehistory.productid = productdetails.productid AND pricehistory.priceeffectiv
(SELECT Maximum(pricehistory.price
FROM productdetails
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks to both of you. Points allocated.
mlmcc