SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2004
    Location
    london
    Posts
    145
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Selecting every Nth record - Access Database

    I need to vreate a query within Access that would allow me to display every Nth record from a table beginning with a vertain record.

    In detail, starting with record ID 22, I want to be able to select ever 21st record after that.

    Any guidance would be greatly appreciated.

  2. #2
    Obey the Purebreed trib4lmaniac's Avatar
    Join Date
    Dec 2004
    Location
    Cornwall, UK
    Posts
    594
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you records are numbered sequentially then you could use the following query:
    Code SQL:
    SELECT *
    FROM TABLE
    WHERE ID - 22 MOD 21 = 0;

  3. #3
    SitePoint Zealot
    Join Date
    Dec 2004
    Location
    london
    Posts
    145
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, but but when I plug WHERE ID - 22 MOD 21 = 0 into the Criteria box within Access I get an "Data type in criteria expression" error.

    I do have an ID field which is sequential (autonumber)
    Last edited by dutton; Apr 15, 2008 at 08:37.

  4. #4
    SitePoint Member
    Join Date
    May 2006
    Location
    Caledon, Ontario, Canada
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dutton View Post
    Thanks, but but when I plug WHERE ID - 22 MOD 21 = 0 into the Criteria box within Access I get an "Data type in criteria expression" error.

    I do have an ID field which is sequential (autonumber)
    Access may be getting a little confused. I would try bracketing, i.e.:

    Code:
    WHERE (([ID] - 22) MOD 21) = 0
    I don't have Access on my current machine but did try it in MySQL. Without brackets, it didn't error out but it didn't return any rows either. With the brackets, it worked.

    Barb


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •