Michael Monashev wrote:

> How to select 5 random rows from big table with WHERE clause?

Maybe something like this:
SELECT col1, col2 FROM table WHERE col3=123 AND (id_col=RAND() OR id_col=RAND() OR id_col=RAND() OR id_col=RAND() OR id_col=RAND())

the problem is that there is the (low) probability of 2 equal id_cols get randomly generated, return only 4 different rows

> This query very slow on 1 mln rows:
> SELECT col1, col2 FROM table WHERE col3=123 ORDER BY RAND() LIMIT 5

but that problem can also occur in your slow query

Note: I have already sent this privatly forgeting to sen do the list

--
Airconditioners and computers have one thing in common: Once you open windows everything fails.

Nuno Pereira

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to