473,398 Members | 2,389 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

At random selection

Hello,

I would like to select/filter at random 30 records out of an
Access-table of 1500 records. I know the option "Top" which gives me
the possibility to see the 30 first records of the table The problem is
that this option is linked to the way of sorting the table. So you will
always select from a very restraint part of the 1500 records.

Is there a possibility
* to select or sort at random in Access. Maybe there exists an
sql-syntax?
* to use a similar function like the funciton Aselect in Excel, which
gives me the possibility to get an number at random

That's the way I resolve at this moment my problem. I export my table
to Excel, I accord an number at random (using the function Aselect) to
each record, I import again in Access and I sort on the number, before
using the function Top. The next time, I use the same procedure to get
another set of records.

I assume there must be an easier way to do it?

Is there anybody who knows another solution?

Thanks in advance

Nov 13 '05 #1
2 4819
This query assumes your table is named "Table1", and it has an AutoNumber
field named "ID":

SELECT TOP 30 Table1.*
FROM Table1
ORDER BY Rnd(Table1.ID), Table1.ID;

For that to be random, you need to issue a Randomize in VBA code before
running the query.

The Rnd() doesn't do anything with the value passed in, but if you don't
pass something the query optimizer is too clever and doesn't bother calling
the function at every row.

The 2nd element of the ORDER BY clause is to prevent more than 30 records
being returned in the (unlikely) event that Rnd() creates duplicates.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"IceCube" <an*********@pandora.be> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
Hello,

I would like to select/filter at random 30 records out of an
Access-table of 1500 records. I know the option "Top" which gives me
the possibility to see the 30 first records of the table The problem is
that this option is linked to the way of sorting the table. So you will
always select from a very restraint part of the 1500 records.

Is there a possibility
* to select or sort at random in Access. Maybe there exists an
sql-syntax?
* to use a similar function like the funciton Aselect in Excel, which
gives me the possibility to get an number at random

That's the way I resolve at this moment my problem. I export my table
to Excel, I accord an number at random (using the function Aselect) to
each record, I import again in Access and I sort on the number, before
using the function Top. The next time, I use the same procedure to get
another set of records.

I assume there must be an easier way to do it?

Is there anybody who knows another solution?

Thanks in advance

Nov 13 '05 #2
Thanks. I've also got the following interesting links.
Maybe for the next one with the same problem?

http://www.fontstuff.com/vba/Vbatut02pfv.htm
www.webbes.dds.nl (download/notsoeasysamples

Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Keith Griffiths | last post by:
I'm trying to do a search under a set criteria followed by a selection of random entries meeting this criteria. But I don't seem to be able to achieve this. The idea being to search on say...
4
by: Bart Nessux | last post by:
New to Python... trying to figure out how to count the objects in a list and then map the count to the objects or convert the list to a dict... I think the latter would be better as I need a number...
9
by: Bart Nessux | last post by:
I am using method 'a' below to pick 25 names from a pool of 225. A co-worker is using method 'b' by running it 25 times and throwing out the winning name (names are associated with numbers) after...
4
by: Jack | last post by:
I have two files: sort_comparison.c++ my_sort.h sort_comparison.c++ calls this code in my_sort.h: void my_sort::fillArray(int arr,int n) { // const int random_number_range=1000000;
1
by: Micak | last post by:
I'm using radnom selection in ms access to select certain number of questions for the exam. i have two versions of the report: - one without marked answers - one with marked answers the problem...
8
by: Kari Lavikka | last post by:
Hi! I have to select a random row from a table where primary key isn't continuous (some rows have been deleted). Postgres just seems to do something strange with my method. -- -- Use the...
5
by: jordi | last post by:
I need the random.sample functionality where the population grows up to long int items. Do you know how could I get this same functionality in another way? thanks in advance. Jordi
19
by: Boris Borcic | last post by:
does x.sort(cmp = lambda x,y : cmp(random.random(),0.5)) pick a random shuffle of x with uniform distribution ? Intuitively, assuming list.sort() does a minimal number of comparisons to ...
1
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I generate a random integer from 1 to N?...
13
by: Bruza | last post by:
I need to implement a "random selection" algorithm which takes a list of as input. Each of the (obj, prob) represents how likely an object, "obj", should be selected based on its probability of...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.