On Wed, Jun 13, 2001 at 03:25:55PM -0600, Matt Heaton wrote:
> I can't seem to find a specificatoin on order by rand() and have a question.
> 
> Lets say a table has 10,000 rows in it, and I want to get one row that
> matches
> 
> so I do a
> 
> select * from table where number=1 order by rand() limit 1;
> 
> 
> What if 100 rows match?  Does it first get all 100 rows and then randomly
> choose one?

Ofcourse.

> Or does it find the first one and stop?  If it finds 100 rows and then
> chooses one this
> is VERY inefficient.  If it finds one and then stops, what determines which
> row it starts
> searching on?

If it stops at the first one, it can't very well return a random one
from the set. It therefore has to find those 100 entries first.

> If anyone knows FOR SURE how this works please let me know... I need to be
> able to grab
> a single row FAST even if a bunch of rows match.  Let me know if you have
> any ideas.

Let's just say the query is executed from left to right quite nicely.
With indexing on 'number' this should be quite fast, still.

Greetz, Peter
-- 
Against Free Sex!   http://www.dataloss.nl/Megahard_en.html

---------------------------------------------------------------------
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