another way to do this without a correlated subquery (and possibly easier to understand) is like this:
SELECT er1.fromCur, er1.toCur, er1.rate, er1.effectiveDate
FROM ExchangeRates er1
INNER JOIN
(SELECT fromCur, toCur, MAX(effectiveDate) as effectiveDate
FROM ExchangeRates
GROUP BY fromCur, toCur) tmp
ON er1.fromCur=tmp.fromCur
AND er1.toCur=tmp.toCur
AND er1.effectiveDate=tmp.effectiveDate
correlated subqueries can be expensive, so check out the estimated execution plan to see which way is more efficient for your table.
rgds
Phil
|