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,774
  • 8
  • 24
  • 33

2 Answers2

4
SELECT id,user_who_posted,quote,year,author FROM table ORDER BY RAND() LIMIT 1
delphist
  • 4,409
  • 1
  • 22
  • 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
  • 24,660
  • 56
  • 77
  • 117