-1

i am making a n application based on quiz therefore i need to select data randomly from database i m using sqlite please help

Noel M
  • 15,812
  • 8
  • 39
  • 47
Ranjeet Sajwan
  • 1,925
  • 2
  • 28
  • 60
  • 1
    You haven't specified it, but probably you also want to ensure that you don't get the same question twice in a row. – Mark Byers Aug 05 '10 at 09:37

4 Answers4

1

You should check RANDOM() function, ex:

SELECT * FROM table ORDER BY RANDOM() LIMIT 1;
Maciej Kucharz
  • 1,395
  • 1
  • 13
  • 17
0
SELECT * FROM table ORDER BY RANDOM()
Andreas
  • 21,535
  • 7
  • 47
  • 56
0
Select * from Table order by random()
Floyd
  • 1,898
  • 12
  • 20
0

To minimise hits on the database, I would suggest reading out all of your questions into a data structure in memory (assuming there's not so many that it would consume all memory).

You could then shuffle the array using a decent shuffle algorithm and pop questions from the array to use.

Jasarien
  • 58,279
  • 31
  • 157
  • 188