Page 1 of 1

[SOLVED] Selecting random "n" entries from a DB

Posted: Fri Jan 28, 2005 8:22 am
by zoki
OK for example, I have a query:

SELECT * FROM news WHERE cat='$cat' LIMIT 5;

The thing is, I want to select 5 random entries. Is that possible?

Posted: Fri Jan 28, 2005 8:29 am
by JayBird
try this

Code: Select all

SELECT * FROM news WHERE cat='$cat' ORDER BY rand() LIMIT 5;

Posted: Fri Jan 28, 2005 8:38 am
by zoki
Yes, that worked. Thanks a lot.