Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8260437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:05:58+00:00 2026-06-08T03:05:58+00:00

I am using a Microsoft Access 2010 database to import values from one table

  • 0

I am using a Microsoft Access 2010 database to import values from one table and append them to a summary table.

One of the issues I am having is finding the previous and next value from the select statement.

This would look as follows.

JOINT          JOINT AHEAD             JOINT BEHIND
100103           200203
200203           300303                  100103
300303                                   200203

I would like to create this using a SQL code

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T03:06:00+00:00Added an answer on June 8, 2026 at 3:06 am

    Be cautious when considering correlated subqueries. They can be very slow. And if you build a query which includes two correlated subqueries, you will magnify the problem.

    If your source table contains a smallish number of rows (say a few dozen), the slowness may not be an issue. However, if the table includes a thousand rows you will most certainly notice it. And if your JOINT field is not indexed, the performance could be painfully slow.

    If you will be running your query from within an Access session, you can use domain functions (DMin and DMax) instead of correlated subqueries. Domain functions are often criticized as slow. However, in this situation they can be dramatically faster than correlated subqueries.

    Correction: You don’t need to run your query from within an Access session for it to be able to use the DMin() and DMax() functions. I attached a VBScript example which opens an ADO Recordset based on my qryDomainFunctions. It works without error and correctly reports RecordCount: 1000

    I created a table, joints, with a long integer field joint as primary key and added 1000 rows. Then I created these 2 queries:

    qryCorrelatedSubqueries:

    SELECT
        a.joint,
        (SELECT TOP 1 joint 
        FROM joints b 
        WHERE b.joint>a.joint 
        ORDER BY joint) AS Ahead,
        (SELECT TOP 1 joint 
        FROM joints b 
        WHERE b.joint<a.joint 
        ORDER BY joint DESC) AS Behind
    FROM joints AS a;
    

    qryDomainFunctions:

    SELECT
        j.joint,
        DMin("joint","joints","joint > " & [joint]) AS joint_ahead,
        DMax("joint","joints","joint < " & [joint]) AS joint_behind
    FROM joints AS j;
    

    Here is a transcript from the Immediate window where I compared the speed of those 2 queries, using the QueryDuration function below. That function returns duration in milliseconds.

    ? QueryDuration("qryDomainFunctions")
     0 
    
    ? QueryDuration("qryCorrelatedSubqueries")
     889
    

    Note that both those queries benefit from the index on the joints field. When I dropped the index, compacted the db, and re-ran the tests I got these results:

    ? QueryDuration("qryDomainFunctions")
     16 
    
    ? QueryDuration("qryCorrelatedSubqueries")
     4570
    

    This is the module with the code I used. QueryDuration is by no means the last word on performance measurement. However it’s good enough to give us a rough idea of the relative speeds of those 2 queries.

    Option Compare Database
    Option Explicit
    
    Private Declare Function apiGetTickCount Lib "kernel32" _
     Alias "GetTickCount" () As Long
    
    Public Function QueryDuration(ByVal pQueryName As String) As Long
        Dim db As DAO.Database
        Dim lngStart As Long
        Dim lngDone As Long
        Dim rs As DAO.Recordset
    
        Set db = CurrentDb()
        lngStart = apiGetTickCount() ' milliseconds '
        Set rs = db.OpenRecordset(pQueryName, dbOpenSnapshot)
        If Not rs.EOF Then
            rs.MoveLast
        End If
        lngDone = apiGetTickCount()
        rs.Close
        Set rs = Nothing
        Set db = Nothing
        QueryDuration = lngDone - lngStart
    End Function
    

    DomainFunctionsQuery.vbs:

    Option Explicit
    Dim cn, rs
    Set cn = CreateObject("ADODB.Connection")
    cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source='database1.mdb'"
    Set rs = CreateObject("ADODB.Recordset")
    rs.CursorLocation = 3 ' adUseClient '
    rs.Open "qryDomainFunctions", cn, 3 ' adOpenStatic = 3 '
    WScript.Echo "RecordCount: " & rs.RecordCount
    rs.Close
    Set rs = Nothing
    cn.Close
    Set cn = Nothing
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Microsoft Access 2010 database(*). Now, using Visual Studio 2010, I want
I am using Microsoft Access database for storing data. In that, I stored date
I am using a table called analyzed in Microsoft Access. It has many fields
How to connect to a Microsoft Access-based database in a Windows using JDBC code?
Am using grids in VB.net to display database records stored in Microsoft Access, the
I have just started using the Data Access Application Block from microsoft. There are
I am new in creating application using Visual Studio 2010 and Microsoft Access 2007.
I am using Microsoft Visual C# 2010 Express. I did not have access to
I'm new creating applications using Visual Studio 2010 and Microsoft Access 2007. I already
I am trying to access the data from MS Access Database using C#. in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.