How to retrieve data with running number using access query ?

Posted on 2004-11-12
Last Modified: 2008-01-09
How to retrieve datas with running number using access query ? eg. i got three data ...then show me 1 ... 2 .. 3 ...
Question by:alankwan
    LVL 26

    Expert Comment

    by:Alan Warren
    Hi alankwan

    If you have a numeric primary key field in your table, autonumber is good, you can do something like this:

    SELECT (Select count(*) from TheTable where ID <=T.ID) AS [Counter], T.ID
    FROM TheTable AS T


    Counter      ID
    1      1
    2      2
    3      3
    4      5


    LVL 1

    Author Comment

    thank you ...but it not works if i got 'where' clause to filter data
    LVL 26

    Accepted Solution

    hi alankwan

    you can put the same whereclause in the sub-select and the select

    SELECT (Select count(*) from TheTable where ID <=T.ID AND TheTable .ID < 100) AS [Counter], T.ID
    FROM TheTable AS T
    Where T.ID < 100


    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
    Read about achieving the basic levels of HRIS security in the workplace.
    Video by: Steve
    Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now