Actually, that didn't work quite as I wanted. In my attempt to oversimplify the example, it's not retrieving all the results I want.
There are several other tables that are linked to the products related to different currencies and weights of a product it can be sold in.
So, I want to be able to retrieve a price for each product in each currency and in each weight.
I also have a weights table like so:-
Weights
Code:
ID ScaleID Amount
1 1 10.000
2 1 50.000
Scales
So the full prices table might look something like
Code:
ID ProductID Price TimeStamp WeightID
1 1 32 11/11/2009 12:35:36 1
2 2 65 11/11/2009 12:36:47 1
3 1 35 11/11/2009 13:25:56 1
4 1 150 11/11/2209 12:37:25 2
In Total I'd want the result to be:-
Code:
ProductID Name Price Weight
1 Blue Widget 150 50
1 Blue Widget 35 10
2 Red Widget 65 10
it was only retrieving one price entry for each product.
I have this query:-
Code:
SELECT
A.ID,
A.Name,
A.Description,
C.CurrencySymbol,
B.Price,
B.DtAdded,
D.Amount,
E.ShortName
FROM tblProducts A
RIGHT JOIN tblProductPrices B
ON (B.ProductID=A.ID AND B.dtAdded=
(SELECT MAX(dtAdded) AS spDtAdded FROM tblProductPrices WHERE tblProductPrices.ProductID=A.ID))
LEFT JOIN tblsysCurrencyCode C ON C.ID=B.CurrencyID
LEFT JOIN tblsysProductWeights D ON D.ID=B.WeightID
LEFT JOIN tblsysWeightScales E ON E.ID=D.ScaleID
This is returning an entry for each weight element and then joining a product to it.
Hope that makes sense. I tried to simplify the explanation to make it easier to understand, but perhaps giving all the facts from the start might have been better. May be a matter of just changing a couple of the JOINS around.
Bookmarks