Last n records for each item

Joined
Oct 18, 2005
Messages
1
Reaction score
0
Hi all,

I have a table of readings from different meters. The fields are ReadingID (autonum for each record); MeterID (unique to each meter); MetDate; Reading.

Each meter will have many readings. What I am trying to do is return the last 3 readings for each meter. I have used TOP on the descending date data but can only get the last 3 records overall, not the last 3 for each meter:

SELECT TOP 3 READINGS.MeterID, READINGS.Reading, READINGS.MetDate
FROM READINGS
ORDER BY READINGS.MetDate DESC;

If I then put a where clause in stipulating the Meter, I can get the last 3 for that meter but I need output showing the last 3 readings for meter1, meter2, meter3 etc.

Hope this makes sense. Any suggestions on how this can be done?

Cheers, Nat
 

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

Top