Page 1 of 1

how to pick 5 random rows

Posted: Fri Nov 17, 2006 2:13 am
by itsmani1
I need to pick 5 rows randomly form the database
how can i do so?

Posted: Fri Nov 17, 2006 3:11 am
by timvw
When will you start to look these things up yourself? I'm pretty sure the order by rand has been mentionned various times overhere... And the limit clause (or whatever it's called for your sql dbms) even more...

even "sql get 5 random rows" returns useful results in a search-engine.
http://www.petefreitag.com/item/466.cfm

Posted: Fri Nov 17, 2006 3:37 am
by phpdevuk
This sort of thing will do what you want.
easily found by googling tho ;)

Code: Select all

SELECT *							
FROM table
ORDER BY RAND()
LIMIT 0,5