Feb 27, 2004 #1 Robert79 Programmer Joined Feb 27, 2004 Messages 2 Location 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.
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.
Feb 27, 2004 #2 PHV MIS Joined Nov 8, 2002 Messages 53,708 Location FR 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 Upvote 0 Downvote
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
Mar 1, 2004 Thread starter #3 Robert79 Programmer Joined Feb 27, 2004 Messages 2 Location US Thank you, PHV. That was perfect! Upvote 0 Downvote