NYCPHP Meetup

NYPHP.org

[nycphp-talk] Random record from MySQL

Ophir Prusak lists at prusak.com
Thu Mar 11 11:07:09 EST 2004


I've never seen this solution before. Very simple.
I wondering though about the efficiency of this solution.

It seems to me that this assigns a random value to each row and then 
orders by that row.
Does the DB do a full table scan using this method?

If yes, this would be a very inefficient method for very large tables.

Ophir


tom at supertom.com wrote:

>Jeff,
>
>Try:
>
>SELECT  * FROM table_name ORDER  BY RAND(  ) LIMIT 0 , 1
>
>Tom
>www.liphp.org
> 
> 
> 
> 
>***************************************************
>What's Tom listening to right now?  Find out here:
>http://www.supertom.com/current_track.php
>
>
>
>
>-----Original Message-----
>From: talk-bounces at lists.nyphp.org
>[mailto:talk-bounces at lists.nyphp.org]On Behalf Of Jeff Siegel
>Sent: Thursday, March 11, 2004 10:32 AM
>To: NYPHP Talk
>Subject: [nycphp-talk] Random record from MySQL
>
>
>How can I pull a record at random from a MySQL table?
>
>Jeff Siegel
>
>_______________________________________________
>talk mailing list
>talk at lists.nyphp.org
>http://lists.nyphp.org/mailman/listinfo/talk
>
>_______________________________________________
>talk mailing list
>talk at lists.nyphp.org
>http://lists.nyphp.org/mailman/listinfo/talk
>  
>



More information about the talk mailing list