473,756 Members | 6,482 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Random selection

Hi all, im a little bit new to all this so i you could help me a little i
would be greatful.

How do i select a completly random record from a database?

sql = select (random) from tbl, sort of thing.

Thanks for any help you can give

Jamie
Jul 19 '05 #1
5 5058
Hi Jamie,

is it ASP ???

you could do something like

select count(*) from tbl, sort of thing

randomize
count = {count varable from select (*)}
random_number=i nt(rnd*count)+1

select from tbl where id = random_number

something like this will do it

Graham

"Jamie Fryatt" <ja**********@b tconnect.com> wrote in message news:bq******** **@titan.btinte rnet.com...
Hi all, im a little bit new to all this so i you could help me a little i
would be greatful.

How do i select a completly random record from a database?

sql = select (random) from tbl, sort of thing.

Thanks for any help you can give

Jamie

Jul 19 '05 #2
PL
> How do i select a completly random record from a database?

The question is what kind of database ? Some databases actually
have a way of doing it directly, if it's SQL server you need to fool
it a bit and the code is not that efficent:

"SELECT TOP 1 [fieldname] from [yourtable] order by newid()"

PL.
Jul 19 '05 #3
Forgive me if I am wrong, but does your suggestion not
require that all the IDs be sequential. If, for instance
you started with 200 records, and deleted every other one,
you would be left with 100 even numbered records. Using
your logic, the count would be 100 and the random_number
might be odd (i.e. 33). Since there is no record ID 33
(remember all odd records were deleted), the query would
return nothing.

Hi Jamie,>select count(*) from tbl, sort of thing

randomize
count = {count varable from select (*)}
random_number= int(rnd*count)+ 1

select from tbl where id = random_number
-----Original Message-----
is it ASP ???

you could do something like

something like this will do it

Graham

"Jamie Fryatt" <ja**********@b tconnect.com> wrote in

message news:bq******** **@titan.btinte rnet.com...
Hi all, im a little bit new to all this so i you could help me a little i would be greatful.

How do i select a completly random record from a database?
sql = select (random) from tbl, sort of thing.

Thanks for any help you can give

Jamie

Jul 19 '05 #4
i am using a standard ms access database!

i just need a select statement for a random record select if there is one?

Thanks

Jamie
"PL" <pb****@yahoo.s e> wrote in message
news:OT******** ******@TK2MSFTN GP09.phx.gbl...
How do i select a completly random record from a database?


The question is what kind of database ? Some databases actually
have a way of doing it directly, if it's SQL server you need to fool
it a bit and the code is not that efficent:

"SELECT TOP 1 [fieldname] from [yourtable] order by newid()"

PL.

Jul 19 '05 #5
Jamie Fryatt wrote:
i am using a standard ms access database!

i just need a select statement for a random record select if there is
one?

http://groups.google.com/groups?hl=e...se&sa=N&tab=wg

HTH,
Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 19 '05 #6

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

Similar topics

4
6290
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 subject and then select a random set of records meeting that subject. Any ideas or thought would be helpful. I'm using Access XP to try this out. TIA
3
3243
by: Andie | last post by:
Hello All, How would I go about using a disconnect recordset and select (x) records from it, x being the number of records to be selected. Many thanks in advance. -- Andie
3
1809
by: Gunnar | last post by:
Hello. Problem: How can I select K random values from the elements 0,1,2,3,4...,N-1 ? I don't know if there's an easy way of doing this, but here are suggestions for doing it. One way is to select K random elements (using a rand()% N), and then see if any number was choosen twice, and then re-select the duplicats until the
1
1547
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 is when i generate the reports one after another, i don't get the same selection of questions. Does anyone knows how to generate two parallel reports that would give the same random selection?
2
4845
by: IceCube | last post by:
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
2
1520
by: Tartifola | last post by:
Hi, I have a list with probabilities as elements with of course p1+p2+p3=1. I'd like to draw a random element from this list, based on the probabilities contained in the list itself, and return its index. Any help on the best way to do that?
13
2366
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 "prob".To simplify the problem, assuming "prob" are integers, and the sum of all "prob" equals 100. For example, items = The algorithm will take a number "N", and a list as
3
2338
by: Manuel Ebert | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Dear list, who's got aesthetic advice for the following problem? I've got some joint probabilities of two distinct events Pr(X=x, Y=y), stored in a list of lists of floats, where every row represents a possible outcome of X and every float in a row a possible outcome of Y (which I will now call my matrix, altough I can't use numpy or numeric for
5
1683
by: DruidWanderer | last post by:
I'm attempting to create a frame that loads a page with a specific variable based on a random number, but I can't seem to get it to work. Any help would be greatly appreciated. Here's what I've got so far: <html> <head> <title>Main Page</title> </head> <frameset rows="100%">
0
1014
by: sentimental37 | last post by:
Hello everybody, I am developing a c# application in which i am using access2007 database. I want to select random records from the database through an access query in c#.but i am not able to do so.the format of my database is as:- tblQuestions-QuestionNo.Question,Ans1,Ans2,Ans3,CorrectAnswer now i want to select random questionNo. and related fields and display them on my form.how to do this.plzzzzzz thanks
0
9462
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10046
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9886
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9722
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8723
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7259
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5155
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2677
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.