Page 1 of 1

How to pull random record from a DB?

Posted: Thu Sep 12, 2002 9:52 am
by Crashin
Hey all...

I'd like to construct a query that will pull a random record from my DB (MySQL) for display on our homepage. Is there a quick and dirty way to do this?

Posted: Thu Sep 12, 2002 10:08 am
by kcomer

Code: Select all

SELECT * FROM table_name ORDER BY RAND() limit 1;
Should work. Got it from the MySQL website. Imagine that.

Keith

Posted: Thu Sep 12, 2002 10:17 am
by Crashin
Aw, shucks! MySQL has their own website??? Why, I never! :oops: Thanks, man! I'll do better research next time...

Posted: Thu Sep 12, 2002 12:15 pm
by kcomer
Just giving you a hard time. Mine will come sometime I'm sure.