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 278023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T01:10:18+00:00 2026-05-12T01:10:18+00:00

I am using MS ACCESS 2003 TABLE NAME –> tmp_cardevent PERSONID CARDEVENTDATE CARDEVENTTIME 5008

  • 0

I am using MS ACCESS 2003

TABLE NAME –> tmp_cardevent

PERSONID   CARDEVENTDATE  CARDEVENTTIME

5008       20090805       080000
5008       20090805       140000
5008       20090809       180000
5008       20090809       220000
3405       20090805       080000
3405       20090805       180000
3405       20090809       070000
3405       20090809       230000
3010       20080806       090000
3010       20080806       230000
3010       20080810       100000
3010       20080810       160000

I want to display Today time and previous day time for the person id
Previous day means not yesterday, previous cardeventtime for the particular person id.

I make the following query for getting previous row value

select t1.Personid, 
    t1.cardeventdate, 
    t1.cardeventtime, 
    t2.Personid,  
    t2.cardeventdate,
    t2.cardeventtime 
from  tmp_cardevent  t1 inner join tmp_cardevent t2 on t1.cardno = t2.cardno 
where t2.cardeventdate =  (
    select max(cardeventdate)  
    from tmp_cardevent ds 
    where ds.cardeventdate < t1.cardeventdate
        and ds.cardno = t1.cardno 
    ) 

From the above query previous row is displaying perfectly

Expected Output

PERSONID   CARDEVENTDATE      LastCARDEVENTDATE  

5008       20090809           20090805       
3405       20090809           20090805       
3010       20080810           20080806     

But if am using group by, order by, sub queries in the above query, it is taking to much time nothing displaying, because it’s so bad in performance in huge amount of data

So can anyone help me to get the best solution for such a problem?

or any other query help?

  • 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-05-12T01:10:18+00:00Added an answer on May 12, 2026 at 1:10 am
    SELECT
       Seq = identity(int, 1, 1),
       CardNo,
       CardEventDate
    INTO #CardSeq
    FROM tmp_cardevent
    ORDER BY CardNo, CardEventDate
    
    SELECT
       t1.Personid,
       t1.cardeventdate,
       t1.cardeventtime,
       t2.Personid,
       t2.cardeventdate,
       t2.cardeventtime
    from
       tmp_cardevent t1
       inner join #CardSeq S1 ON t1.CardNo = S.CardNo
       left join #CardSeq S2 ON t1.CardNo = t2.CardNo and t1.Seq - 1 = t2.Seq
       left join tmp_cardevent t2 on t1.cardno = t2.cardno
    
    DROP TABLE #CardSeq
    

    Putting an index on the temp table on CardNo and/or Seq should help. Creating the temp table with the indexes before filling it is probably better than adding the indexes after using SELECT INTO. Experiment with a clustered index only on each column, then clustered on one column + nonclustered on the other and vice versa to see what gives the best performance.

    If you have conditions on the query to limit the card numbers, do this on the insert to the temp table so it only works on what’s necessary.

    The left joins are needed otherwise the first event will never show up.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using MS - Access 2003 Table S.No Details 1 name 2 address 3 email
Using VB6 and Access 2003 Query Select Temp.* into NewTable from Temp Table Name
Using SQL server 2000 and Access 2003 Access Database Name - History.mdb Access Table
Using Access 2003 Table1 ID Name Value 001 Raja 100 002 Ramu 200 004
Using Access 2003 Table1 Personid Date1 101 02-02-2008 102 02-02-2008 103 02-02-2008 101 03-02-2008
I am using MS Access 2003. I want to run a lot of insert
I am using DoCmd.SendObject to send emails from MS access 2003. It opens the
I am working with an Access 2003 database that has a subroutine using DAO
Is there a way to copy an Access 2003 pivot table view (used to
So I have an access mdb file that was originally create using Access 2003/Office

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.