PDA

View Full Version : Getting something random out of mysql ?



jvv
December 21st, 2000, 03:28
I'm trying to grab a random article out of a mysql database, and the article must match certain search criteria (ie. not be older than 7 days and match a lookup number 1,2 or 3 which tells if the article is to be a main article, sub or just the title has to be displayed)...

I need to know if there is a relatively easy way to pull something random out of the DB answering to the search criteria...

ashben
December 21st, 2000, 06:58
If you (or your host) are running MySQl 3.23+ then you can use the following SQL for fetching a random row of a table (say X) :

select * from X order by rand() limit 1