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!

get second to last record in file

Status
Not open for further replies.

Robert79

Programmer
Feb 27, 2004
2
US
Hi,
I would like to know how to retieve the second to last record in a file. (Not the last record, but the one right before it.)
Thank you.
 
To retieve the second to last row in a table myTable with primary key myPK, you can try something like this:
Code:
SELECT * FROM myTable
 WHERE myPK=(
       SELECT MAX(myPK) FROM myTable
        WHERE myPK<(SELECT MAX(myPK) FROM myTable)
)

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top