Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Randomly select list of records from a table

Status
Not open for further replies.

cantona

Technical User
May 20, 2001
121
GB
Im wanting to produce something in Access that will randomly select a number of records from a table. I would like for example to input into a form the number of records I would like to select randomly.. say 20. Then get a list of 20 random records from a particular table. Im really not sure where to start with this! The table I want to use is called registrations, and the field name I would like to sample is registration_ID. Is this possible?
 
Here's something I found in the Ye Olde Code Vault:

Returns 10 random records

SELECT TOP 10 Rnd(Len([PrimaryKeyField])) AS Expr1,YourTable.PrimaryKeyField,YourTable.Field1,YourTable.Field2,YourTable.Field3
FROMYourTable
ORDER BY Rnd(Len([PrimaryKeyField])) DESC;


The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top