By user1169809

2012-03-30 04:58:06 8 Comments

I have a MS access database. In that, one table consists of questions and answers with primary key questionID. I need to retrieve random question from that table using questionID. What keywords or query should I use for this scenario.


@Yauhun 2017-03-29 07:28:19

SELECT TOP 5 questionID FROM [tableName] ORDER BY rnd(INT(NOW*questionID)-NOW*questionID)

This will give you a new set of answers every time, you don't even need to make up a time when you use "NOW" (which will every time be a new time you click this no matter how fast you click), in my opinion the most simple and neat way to solve this in Access.

@MatVAD 2017-11-01 06:19:12

This one works perfectly okay for me. All other methods gives the same set of records. Good work.

@bummi 2013-10-21 11:18:07

To get different random record you can use, which would require a ID field in your table

SELECT TOP 1 questionID FROM questions ORDER BY Rnd(-(100000*questionID)*Time())

A negative value passed as parameter to the Rnd-function will deliver the first random value from the generator using this parameter as start value. (A kind of defined randomize). Special thanks to @kobik 's hint from the comments.

@kobik 2013-10-21 11:41:11

Funny thing. I have tested all suggested answers including this I get different/random records. but as soon as I run my test program again the results are in the same sequence as before. as if the random seed generator resets each time in ms-access. I later found this: Random Number Generator Query Not So Random

@Glen Morse 2013-10-21 11:59:13

it does same thing bummi, each time i run it i get the same 4 results

@Glen Morse 2013-10-21 12:00:43

so how you suggest to fix @Kobik

@kobik 2013-10-21 12:04:43

@GlenMorse, There is a working workaround (Bummi, you might wan to edit your answer): ORDER BY NEWID() in MS Access. so using a negative number with Rnd() "fixes" the problem. use: ORDER BY Rnd(-(1000*ID)*Time())

@SuperRod 2012-03-30 05:03:50

The following will get a random questionID from your table


SELECT questionID FROM questions ORDER BY RAND() LIMIT 1

MS Access

SELECT top 1 questionID from questions ORDER BY rnd(questionID)

@kneidels 2013-08-05 13:33:42

the version for MS Access, does seem to generate random records - but the same ones each time!

@Glen Morse 2013-10-21 11:15:37

AGREE.. same random records

Related Questions

Sponsored Content

33 Answered Questions

[SOLVED] How can I generate random alphanumeric strings?

  • 2009-08-27 23:07:24
  • KingNestor
  • 745482 View
  • 1005 Score
  • 33 Answer
  • Tags:   c# .net random

24 Answered Questions

[SOLVED] Getting a random value from a JavaScript array

  • 2010-12-29 00:04:44
  • Sarah
  • 538619 View
  • 811 Score
  • 24 Answer
  • Tags:   javascript random

56 Answered Questions

[SOLVED] How to randomize (shuffle) a JavaScript array?

32 Answered Questions

[SOLVED] How do I generate a random int number?

  • 2010-04-24 23:09:11
  • Rella
  • 2343624 View
  • 1958 Score
  • 32 Answer
  • Tags:   c# random

66 Answered Questions

[SOLVED] How do I generate random integers within a specific range in Java?

  • 2008-12-12 18:20:57
  • user42155
  • 4112863 View
  • 3550 Score
  • 66 Answer
  • Tags:   java random integer

14 Answered Questions

[SOLVED] How to randomly select an item from a list?

  • 2008-11-20 18:42:21
  • Ray
  • 1429909 View
  • 1793 Score
  • 14 Answer
  • Tags:   python list random

42 Answered Questions

[SOLVED] How to generate a random alpha-numeric string?

17 Answered Questions

[SOLVED] How to get a random number in Ruby

Sponsored Content