Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6048021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:24:59+00:00 2026-05-23T07:24:59+00:00

I have a large table and want to create a smaller table that systematically

  • 0

I have a large table and want to create a smaller table that systematically picks out one of every 5 records from the original. How best to do this?

This means it should have every row with id ending in 0 and 5 for example.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T07:25:00+00:00Added an answer on May 23, 2026 at 7:25 am

    Assuming that your IDs as auto-incremented and continuous (with no deleted records), the simplest way could something like:

    SELECT * 
    FROM BigTable 
    WHERE ID Mod 5 = 0
    

    You would insert that into the small table like this:

    INSERT INTO SmallTable
        SELECT * 
        FROM BigTable 
        WHERE ID Mod 5 = 0
    

    If your primary key ID is not sequential you can do this:

    SELECT BigTable.*
    FROM   (SELECT ID,
                   (SELECT COUNT(ID) + 1
                    FROM   BigTable AS A
                    WHERE  A.ID < B.ID) AS RowNum
            FROM   BigTable AS B) AS C
           INNER JOIN BigTable
             ON C.ID = BigTable.ID
    WHERE  RowNum Mod 5 = 0
    

    Note though that this is OK for a one-time thing as it is quite slow if you have a lot of records.

    Better do it in code if you have lots of records (or maybe you have no primary key, which is usually bad btw).
    The code below is generic code to copy all records from one table into another (existing) table:

    Public Sub CreateSmallTable(largeTableName As String, _
                                smallTableName As String, _
                                interval As Integer)
        Dim rsL As DAO.RecordSet
        Dim rsS As DAO.RecordSet
        Dim db As DAO.Database
        Dim rowNum As Integer
        Set db = CurrentDb()
        ' Open the LargeTable in read-only mode '
        Set rsL = db.OpenRecordset(largeTableName, dbOpenSnapshot)
        If Not (rsL Is Nothing) Then
            Set rsS = db.OpenRecordset(smallTableName, dbOpenTable, dbAppendOnly)
            With rsL
                ' We'll use a generic way to copy all fields from the BigTable '
                Dim fd As DAO.field
                Dim flds As DAO.Fields
                Set flds = rsL.Fields
                .MoveFirst
                ' For each record in the BigTable '
                Do While Not .EOF()
                    If rowNum Mod interval = 0 Then
                        rsS.AddNew
                        ' Copy all fields from BigTable to SmallTable '
                        For Each fd In flds
                           rsS.Fields(fd.Name) = .Fields(fd.Name)
                        Next fd
                        rsS.Update
                    End If
                    rowNum = rowNum + 1
                    .MoveNext
               Loop
               .Close
            End With
            rsS.Close
            Set rsS = Nothing
            Set rsL = Nothing
        End If
    End Sub
    

    And call it like that (assuming that both BigTable and SmallTable have the same structure and that there are no existing records in SmallTable that could create a primary key violation when trying to inster duplicate records):

    CreateSmallTable "Bigtable", "Smalltable", 5
    

    Edit: following HansUp response, changed SQL queries to use Mod instead of its functional version: (Round(ID/5) = ID/5). He’s right, no need to make it more complex than it needs to be.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a view that I want to create a table from in SQL
I have a large table of birthdays that I want to convert from a
I have a large (multi-GB) data file exported from an Oracle table. I want
I have a large table I want to include in a LaTeX document. It
I have a large table with 1 million+ records. Unfortunately, the person who created
I have a large table (more than 10 millions records). this table is heavily
I have a large table with list of scores like this, one score per
I have a large table I imported from an Excel spreadsheet. For five of
I have a large table (~1M rows now, soon ~10M) that has two ranked
I have a large table consisting of over 60 millions records and I would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.