2

I have a database that holds quotes, i.e Mysql " id,user_who_posted,quote,year,author " I would like to make it show a random quote by id.Is this possible?

Steven Hammons
  • 1,744
  • 8
  • 24
  • 32

2 Answers2

4
SELECT id,user_who_posted,quote,year,author FROM table ORDER BY RAND() LIMIT 1
delphist
  • 4,367
  • 1
  • 21
  • 22
  • If your dataset is huge, consider this: http://stackoverflow.com/questions/1823306/mysql-alternatives-to-order-by-rand – Mike B Feb 27 '11 at 03:34
2
SELECT id,user_who_posted,quote,year,author 
FROM table
ORDER BY RAND()
LIMIT 1

more randoms at http://www.petefreitag.com/item/466.cfm

bensiu
  • 22,720
  • 51
  • 71
  • 112