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) probabi
Privet!
> But this query can return empty results, if we use it with WHERE:
Yes, it can. However, we're able to change the technique and obtain
one random record with WHERE condition in query. With several iterations
it is possible to get several random records.
First we should get the
Hello
GP> Similar questions have been asked before. For example:
GP> http://lists.mysql.com/mysql/184088
Thank you. I found something interesting:
SELECT @rand_id:= CAST( 1 + MAX(id)*RAND() AS UNSIGNED) FROM history;
SELECT * FROM history WHERE id >= @rand_id LIMIT 1;
But this query can retur
Put a index on col3 and it will be faster. That's the only way as far as I
know.
--
Chris.
- Original Message -
From: "Michael Monashev" <[EMAIL PROTECTED]>
To:
Sent: Wednesday, July 20, 2005 3:04 PM
Subject: random rows selection
Hello,
How to select 5
Hello.
Similar questions have been asked before. For example:
http://lists.mysql.com/mysql/184088
Search in archives at:
http://lists.mysql.com/mysql
Michael Monashev <[EMAIL PROTECTED]> wrote:
> Hello,
>
> How to select 5 random rows from big table with WHERE claus
Hello,
How to select 5 random rows from big table with WHERE clause?
This query very slow on 1 mln rows:
SELECT col1, col2 FROM table WHERE col3=123 ORDER BY RAND() LIMIT 5
Have you a faster one?
Sincerely,
Michael,
http://xoib.com/ http://3d2f.com/
http://qaix.com/ http://ryxi.com/
http://g