We help IT Professionals succeed at work.

Select Next to Last record...

Hopefully simple - I need a select statement to pull back one record - the next to the last one...
I'm doing this in Visual Studio, so I don't think BOTTOM is valid, but have tried desc order and still can't seem to get it working...help?
Comment
Watch Question

Top Expert 2010
Commented:
Hello sirbounty,

Assuming you have an ID or datetimestamp that provides a unique and sequential marker...

SELECT TOP 1 z.*
FROM
      (SELECT TOP 2 *
      FROM SomeTable
      ORDER BY ID DESC) z
ORDER BY z.ID

Regards,

Patrick
Top Expert 2007

Author

Commented:
Nice - it just hit me moments ago, but as I went to delete, I got the message that I couldn't, so you win by mere nanoseconds!  Thanks!
Top Expert 2010

Commented:
sirbounty,

:)

Patrick