Solved

sql Next to last Record

Posted on 2006-10-20
8
1,112 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
Industry Leaders: 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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Crystal reports login after closing form 3 56
Need help with a query 3 49
vb.net datagrid point 4 33
reading an excel file vb.net 2 46
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…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…

732 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