-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,312
  • 7
  • 37
  • 45
Ranjeet Sajwan
  • 1,916
  • 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,265
  • 1
  • 11
  • 17
0
SELECT * FROM table ORDER BY RANDOM()
Andreas
  • 20,797
  • 7
  • 44
  • 55
0
Select * from Table order by random()
Floyd
  • 1,888
  • 12
  • 19
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
  • 57,879
  • 30
  • 158
  • 187