• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1124
  • 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
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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