Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select last three records in a recordset

Status
Not open for further replies.

sbbrown9924

Technical User
Mar 7, 2003
80
US
How would I select the last three records in a recordset?
 
Never mind....

Select LAST(TriageTime) AS LastTime, LAST(TriageTime) - 1 As SecondLastTime FROM....
 
mp9;

Cool. That works great!

Do you have a good reference source you can recommend? I cannot find any information about TOP in ADO, VBscript, ASP or JET SQl reference guides. Is TOP part of VB basic? Thanks again.

 
What if I want to compute the average of the three values derived from this query?

SELECT TOP 3 round(DateDiff('n', DispositionTime, NOW())/60,2) AS TopThree
FROM TrackingMain
WHERE DateDiff('n', DispositionTime, now()) > 120 AND AdmittingService=1
 
TOP is part of JET SQL.

Open you Access Help file and, from the Contents tab, expand Microsoft JET SQL Reference. Under Overview you'll find a topic called SQL Reserved Words. You'll find a clickable link for Top there.

Alternatively, for a quick summary of all you need to know about Top.
 
SELECT AVG(TopThree) As TopThreeAvg FROM (SELECT TOP 3 round(DateDiff('n', DispositionTime, NOW())/60,2) AS TopThree
FROM TrackingMain
WHERE DateDiff('n', DispositionTime, now()) > 120 AND AdmittingService=1)

Leslie

Anything worth doing is a lot more difficult than it's worth - Unknown Induhvidual

Essential reading for anyone working with databases:
The Fundamentals of Relational Database Design
Understanding SQL Joi
 
mp9, lespaul;

Ah, the missing link! In the reference guides I use, they don't mention reserved words. Thank for helping me withe query.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top