473,406 Members | 2,371 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,406 software developers and data experts.

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 5041
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=int(rnd*count)+1

select from tbl where id = random_number

something like this will do it

Graham

"Jamie Fryatt" <ja**********@btconnect.com> wrote in message news:bq**********@titan.btinternet.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**********@btconnect.com> wrote in

message news:bq**********@titan.btinternet.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.se> wrote in message
news:OT**************@TK2MSFTNGP09.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
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...
3
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
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...
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...
2
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...
2
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...
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...
3
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...
5
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...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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,...
0
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...

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.