I have a table of contracts and a table of prices. For the purpose of this test the contracts are just contractid and name. The prices table contain records in the format: contractid, AsAt, Price.
prices.contract and prices.AsAT make up the primary key so each contract will have multiple records in the price table but only ever 1 price for any given day.
What I am trying to do is produce a recordset showing the latest date a contract has a price for.
The SQL :
SELECT contract, AsAt
FROM arc_pri_prices
WHERE contract = 1
ORDER BY AsAT DESC
LIMIT 0,1
will give me the latest date for a given contract but I need this for every contract. I'm thinking sub queries is the answer but I seem to be going in circles. Can anyone point me in the right direction please.
prices.contract and prices.AsAT make up the primary key so each contract will have multiple records in the price table but only ever 1 price for any given day.
What I am trying to do is produce a recordset showing the latest date a contract has a price for.
The SQL :
SELECT contract, AsAt
FROM arc_pri_prices
WHERE contract = 1
ORDER BY AsAT DESC
LIMIT 0,1
will give me the latest date for a given contract but I need this for every contract. I'm thinking sub queries is the answer but I seem to be going in circles. Can anyone point me in the right direction please.