Solved

sql Next to last Record

Posted on 2006-10-20
8
1,110 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
  • 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
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 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