Solved

sql Next to last Record

Posted on 2006-10-20
8
1,113 Views
Last Modified: 2007-12-19
Greeting

I cant figure out a query that retrieves only the next to last record where the account number = some value  ( not the last record inserted into the dbase)

Im using vb 2005 and access

Any idea's ?

0
Comment
Question by:stephenz43
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 Comments
 
LVL 12

Expert Comment

by:guidway
ID: 17778825
I think this will work

Select acct_id from [sometableName] where acct_id < [some value] order by acct_id DESC;

then just grab the first record returned and that should be the second to last;
0
 

Author Comment

by:stephenz43
ID: 17778869
hey guidway....

Getting close, but can [some value] be obtained using max[acct_id) ?

steve
0
 
LVL 12

Expert Comment

by:guidway
ID: 17778897
you could try a subquery

Select acct_id from [sometableName] where acct_id < (Select max(acct_id) from [sometableName]) order by acct_id DESC
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Accepted Solution

by:
guidway earned 500 total points
ID: 17778903
should be a semicolon at the end

Select acct_id from [sometableName] where acct_id < (Select max(acct_id) from [sometableName]) order by acct_id DESC;

(this was tested in access, not sure which database you are using)
0
 
LVL 12

Expert Comment

by:guidway
ID: 17778912
oops you said access... sorry. ;)
0
 
LVL 13

Expert Comment

by:newyuppie
ID: 17780580
max function does work in access i believe
0
 
LVL 12

Expert Comment

by:guidway
ID: 17780988
glad it worked for you. :)
0
 

Author Comment

by:stephenz43
ID: 17782540
thank you for the help...You saved me alot of aggravation

take care
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question