Does anyone know of a way, using a query to nth a table. I want to randomly select a group of records in a large database….say something like 50 out of 1000, but it must be random.
Any help would be muchly appreciated…
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » How to nth a table in a query??? (2000 )
Check out the Knowledge Base article Q210616 here for an example of this using DAO.
As an aside, we considered using this same kind of functionality to generate a list of people for DOT mandated drug tests, but decided to place the legal liability on a 3d party application; just a thought.
the only way that springs to mind would be to create a proceedure that randomly selects an individual id from the table in question and pops this into an array. Once this array is full of the requisite number of record id’s then run a second query to select the data that you want where the id id in the array. somethin along this pseudo code :
sub GetRandomData
intRowCount = number of rows in table
for x = 1 to 50
generate random number between 0 and intRowCount
arrayofnumbers=GetRandomID(random number)
next x
‘array now full of random id’s
create database connection and recordset
on query like:
select fields from table where id in arrayofnumbers
output data, put data in temporary table for reporting, etc
end sub
function GetRandomId(random number)
select top(1) id from table where id = random number
GetRandomNumber=query result
end function
hope this helps, there may well be holes in this as it is 11:15 pm and it has been a long day ! zzzzzzzzzzzzzz
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.
Notifications