[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 894
  • Last Modified:

How to retrieve data with running number using access query ?

How to retrieve datas with running number using access query ? eg. i got three data ...then show me 1 ... 2 .. 3 ...
0
alankwan
Asked:
alankwan
  • 2
1 Solution
 
Alan WarrenCommented:
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

Returns:

Counter      ID
1      1
2      2
3      3
4      5

Alan

0
 
alankwanAuthor Commented:
thank you ...but it not works if i got 'where' clause to filter data
0
 
Alan WarrenCommented:
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

Alan
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now