473,406 Members | 2,217 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 Record

Hello,

I am trying to use a SQL Query to return a random record from an
Access 2000 Database.

I am using:

SELECT TOP 1 Example
FROM TABLE
ORDER BY Rnd[(ID)];

But, I am not getting a random record, I get the same record returned
each time. If I create a SQL query in Access, and use the order by
rnd, I will get a random record.

Does anyone know how to return a random record with a SQL query?

Thank you for the help,
Bill Kramer
Nov 13 '05 #1
7 6895
I have no idea on how this works, but I did find a solution (I think)

Try:
Nov 13 '05 #2
Sorry, previous post left me too fast...

Here is the syntax (x = table, ID = field)
SELECT TOP 1 x.ID
FROM x
ORDER BY Rnd([id])*[id]*Now();

This works for me
Nov 13 '05 #3
Thank you very much for your reply. Unfortunately I wasn't able to get
your code to work for me. I haven't found a solution yet.

But thank you very much for your effort.

-Bill Kramer
"WindAndWaves" <ac****@ngaru.com> wrote in message news:<P4******************@news.xtra.co.nz>...
Sorry, previous post left me too fast...

Here is the syntax (x = table, ID = field)
SELECT TOP 1 x.ID
FROM x
ORDER BY Rnd([id])*[id]*Now();

This works for me

Nov 13 '05 #4
This works, but it always pulls the same data! I guess the starting
SEED is not accurate?

WindAndWaves wrote:
Sorry, previous post left me too fast...

Here is the syntax (x = table, ID = field)
SELECT TOP 1 x.ID
FROM x
ORDER BY Rnd([id])*[id]*Now();

This works for me


Nov 13 '05 #5
This works, but it always pulls the same data! I guess the starting
SEED is not accurate?

WindAndWaves wrote:
Sorry, previous post left me too fast...

Here is the syntax (x = table, ID = field)
SELECT TOP 1 x.ID
FROM x
ORDER BY Rnd([id])*[id]*Now();

This works for me


Nov 13 '05 #6
You need to use the Randomize method first. Check the Help file.

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
re******@pcdatasheet.com
www.pcdatasheet.com
"gmsmstr" <dm*******@surdyke.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
This works, but it always pulls the same data! I guess the starting
SEED is not accurate?

WindAndWaves wrote:
Sorry, previous post left me too fast...

Here is the syntax (x = table, ID = field)
SELECT TOP 1 x.ID
FROM x
ORDER BY Rnd([id])*[id]*Now();

This works for me

Nov 13 '05 #7
The ORDER BY clause does not affect which records are chosen, only the order
in which the records that have been selected are presented. You would need a
WHERE or HAVING clause to affect the selection.

Just for the record, RANDOMIZEing prior to executing this SQL will have no
effect on the records returned.

Larry Linson
Microsoft Access MVP
"gmsmstr" <dm*******@surdyke.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
This works, but it always pulls the same data! I guess the starting
SEED is not accurate?

WindAndWaves wrote:
Sorry, previous post left me too fast...

Here is the syntax (x = table, ID = field)
SELECT TOP 1 x.ID
FROM x
ORDER BY Rnd([id])*[id]*Now();

This works for me

Nov 13 '05 #8

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...
10
by: Stefanie | last post by:
Hi, I have a question about declaring variables for writing data to a file for random access. I have two string variables declared in a module (user-defined types). The point is that for one of...
2
by: Ini | last post by:
Hi, Is there an easy way to pick at random one record out of a recordset and then leave this recordset? I was thinking about doing a recordcount of the recordset, then find at random the...
4
by: anita | last post by:
I had posted this question before, but did not hear from anybody. Can somebody pls help me out. I am creating a table with two fields F1, F2 and F2 has about 50,000 randomly generated alphanumeric...
2
by: sugaray | last post by:
I want to write a school computer billing system, one of the function is to distribute machine id using rand() for each student log on, suppose there's 100 machines, when each person log on, the...
2
by: Pete via DotNetMonster.com | last post by:
Hi, I need to display a different random record or link each day. I have the random part working so that if the browser is refreshed a new record will display. I'm not sure however how to...
26
by: Jimmy | last post by:
ill have a database with 1 table and 3 fields: ID FIRSTNAME LASTNAME (the ID field will be the auto incrementing index) there might be 10 records in the DB, there might be 10,000. i...
48
by: Jimmy | last post by:
thanks to everyone that helped, unfortunately the code samples people gave me don't work. here is what i have so far: <% Dim oConn, oRS, randNum Randomize() randNum = (CInt(1000 * Rnd) + 1) *...
3
by: John Fairhurst | last post by:
Hi, The following code should select the specified number of records randomly from the database <% .... query = "SELECT FROM " Set RS = Server.CreateObject("ADODB.Recordset")
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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
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
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...

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.