Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 SELECT the second to last record

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-09-05 : 09:33:27
Craig writes "hi there,

i am trying to select the second to last record form our sq db. here's what i have:

SELECT * FROM tbl_Txt
WHERE id = (SELECT MAX(id) - 1 FROM tbl_Txt);

it works ok, however if the primary key isn't consecutive i.e. 91, 92, 93, 94 then the script will not be able to select record 92 if 93 has been deleted.

does anyone have a more fool proof approach to this query?

thanks in advance.
Craig"
   

- Advertisement -