473,289 Members | 2,087 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,289 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 6868
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")
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.