Share via

comparing values with previous record

Anonymous
2012-07-11T19:51:52+00:00

how do i compare a value in a record with a value in the previous record in the same table?

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

3 answers

Sort by: Most helpful
  1. Anonymous
    2012-07-12T14:30:00+00:00

    Sure, but you'll need to elaborate on the nature of the comparison.

    Short answer: you can create a one-field subquery by typing something like

    PreviousX: (SELECT X.Somefield FROM yourtable AS X WHERE X.datefield = (SELECT Max(Y.Datefield) FROM yourtable AS Y WHERE Y.datefield < yourtable.datefield))

    or

    PreviousX: (SELECT TOP 1 X.Somefield FROM yourtable AS X WHERE X.datefield < yourtable.datefield ORDER BY X.datefield)

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2012-07-12T14:17:58+00:00

    Thanks John.  We have one table with an autonumber primary key field.  The field we want to compare is a date time field.  The records are in date time ascending sequence.  Could you elaborate re. the subquery or non-equi join process?  Thanks.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2012-07-11T20:18:16+00:00

    You'll need some way to define "previous". Access tables (and all proper relational tables!) have no defined order; they should be viewed as an unordered "bag" of records.

    You will need some field or combination of fields in the table to specify the sort order that's meaningful in your case. This could be a sequential Autonumber, a timestamp, perhaps some other fields appropriate for your case.

    You can then use a subquery or a non-equi join to bring the two records together for comparison.

    Was this answer helpful?

    0 comments No comments