You might be able to do something like this instead:

  SELECT *, id*0+RAND() AS r FROM table ORDER BY r LIMIT 5;

Check the list archives, this issue comes up quite often.


On Wed, 9 May 2001, Webmaster wrote:

> i dont follow step #3.
> 
> 
> At 11:42 PM 5/8/2001, Tony Shiu wrote:
>  >i think it is more suitable to do it in programming level in mysql, though I
>  >know there is a function is M$sql server.
>  >
>  >if your table schema has a unique id field, before submit a query to DB,
>  >1) select count(*) from it
>  >2) from the above resultset, program to draw whatever number of records you
>  >want.
>  >3) submit the query, select * from it where id in (your random record ids);
>  >
>  >
>  >----- Original Message -----
>  >From: "Webmaster" <[EMAIL PROTECTED]>
>  >To: <[EMAIL PROTECTED]>
>  >Sent: Wednesday, May 09, 2001 11:38 AM
>  >Subject: SQL help
>  >
>  >
>  >> How do I write SQL in MySQL to randomly select 5 records from a table?
>  >>



---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to