Random Entries

I have a table of articles and I want to grab 3 at random - is there a
way I can do this using SQL or will I have to get all results out then
pick them at random using PHP (something like rand() based on the size
of the result set?)

Any other approach anyone can recommend?

Rick
thehuby [ Fr, 05 Januar 2007 22:01 ] [ ID #1586080 ]

Re: Random Entries

thehuby wrote:
> I have a table of articles and I want to grab 3 at random - is there a
> way I can do this using SQL or will I have to get all results out then
> pick them at random using PHP (something like rand() based on the size
> of the result set?)

SELECT .... ORDER BY RAND() LIMIT 3
--
Rik Wasmus
Rik [ Fr, 05 Januar 2007 22:24 ] [ ID #1586081 ]

Re: Random Entries

Sir, you are a legend.

Rick

Rik wrote:

> thehuby wrote:
> > I have a table of articles and I want to grab 3 at random - is there a
> > way I can do this using SQL or will I have to get all results out then
> > pick them at random using PHP (something like rand() based on the size
> > of the result set?)
>
> SELECT .... ORDER BY RAND() LIMIT 3
> --
> Rik Wasmus
thehuby [ Fr, 05 Januar 2007 22:39 ] [ ID #1586083 ]
PHP » alt.php.sql » Random Entries

Vorheriges Thema: SELECT selects too quick
Nächstes Thema: Problem retrieving and displaying whitespaces in php myql