Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

is it possible to select random record from a table?

Status
Not open for further replies.

elvanace1

MIS
Sep 26, 2005
32
0
0
US
Is is possible to write a query that will select records from a table randomly?
 
Have a look at the Rnd function.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Rnd() generates a random number, but what if the table's index is alpha-numneric. How do you get a random record?
 
One way:
SELECT TOP 1 ... ORDER BY Rnd([Any numeric field])

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
But if there is no purely numeric field, what then?

Easiest answer might be to add a numeric field to the table.

Another option would be to use Asc() on several characters of a character field or Cdbl() on a date field.

Or you could use DAO and do a MoveFirst() followed by a lot of random calls to Move()

Geoff Franklin
 
SELECT TOP 1 ... ORDER BY Rnd(Val([Any field]))

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
SELECT TOP 1 ... ORDER BY Rnd(Val([Any field])" is perfect!
Thanks sooo much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top