Results 1 to 5 of 5
  1. #1
    uscpa is offline Novice
    Windows 7 Access 2007
    Join Date
    Jan 2010
    Posts
    1

    Random sampling

    I have a huge database of millions of records and would like to get a random sample of 100 rows for testing. Can somebody help me in building a query for random sampling.



    Thanks,

  2. #2
    ConneXionLost's Avatar
    ConneXionLost is offline Simulacrum
    Windows XP Access 2003
    Join Date
    Jan 2010
    Location
    Victoria, Canada
    Posts
    291
    Hi uspca,

    Assuming your table has a Primary Key and it is numerical, build a query from your table showing the fields you want to see, and add this as a calculated field:

    Code:
    RandomSample: Rnd([uspcaID])
    Sort ascending on this field and set the "Top Values" to 100.

    You don't need to show the RandomSample field in the result.

    Each time you run this query you will get a new random set of 100 records.

    Note - If your table doesn't have a numerical Primary Key (Aaack!!) then just add one using an autonumber.

    Cheers,

  3. #3
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Don't you have to execute a Randomize somewhere to change the seed?

  4. #4
    ConneXionLost's Avatar
    ConneXionLost is offline Simulacrum
    Windows XP Access 2003
    Join Date
    Jan 2010
    Location
    Victoria, Canada
    Posts
    291
    Hi RG,

    Not that I'm aware of. I set this up on a test database and the random numbers appeared to reset each time I ran the query. However, I certainly can't "guarantee" true randomness with this approach.

    Cheers,

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Thanks for the update.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Selecting random with exclutions
    By owutne in forum Queries
    Replies: 1
    Last Post: 02-03-2010, 09:33 PM
  2. Random Rdn() Funtion Help Please
    By graviz in forum Access
    Replies: 1
    Last Post: 12-09-2009, 11:57 AM
  3. Random numbers
    By Gator777 in forum Access
    Replies: 3
    Last Post: 08-12-2009, 10:04 AM
  4. random record
    By wasim_sono in forum Programming
    Replies: 1
    Last Post: 02-06-2008, 02:42 PM
  5. generating random numbers on form
    By anitra in forum Forms
    Replies: 1
    Last Post: 02-14-2006, 10:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums