Add a auto-increasing column to access query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • adamnorsworthy
    New Member
    • Feb 2014
    • 3

    Add a auto-increasing column to access query

    I would like to add a 'rank' field to a query. I have a simple query that orders the results based on a field called 'score'. I want to add another field than than auto-fills with 1 for the first record, then 2, for the second, etc... so it shows a rank position. I have tried creating a field using the following - rank: [rank]+1 but no luck. Any ideas?
  • Seth Schrock
    Recognized Expert Specialist
    • Dec 2010
    • 2965

    #2
    If you have data like the following
    Code:
    ID   Score
    11   90
    12   89
    13   89
    14   85
    Do you want the resulting rank to be
    Code:
    1
    2
    3
    4
    or
    Code:
    1
    2
    2
    4
    I'm going to assume the first based on what you tried. The other only adds a little bit to the query.

    Code:
    SELECT ID
    , Score
    , DCount("*", "YourTable", "ID <= " & ID) As Rank
    FROM YourTable
    ORDER BY ID

    Comment

    Working...