[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1119
  • Last Modified:

sql Next to last Record

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
stephenz43
Asked:
stephenz43
  • 5
  • 2
1 Solution
 
guidwayCommented:
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
 
stephenz43Author Commented:
hey guidway....

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

steve
0
 
guidwayCommented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
guidwayCommented:
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
 
guidwayCommented:
oops you said access... sorry. ;)
0
 
newyuppieCommented:
max function does work in access i believe
0
 
guidwayCommented:
glad it worked for you. :)
0
 
stephenz43Author Commented:
thank you for the help...You saved me alot of aggravation

take care
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now