Re: random rows selection

2005-07-21 Thread Nuno Pereira
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

Re: random rows selection

2005-07-21 Thread Gleb Paharenko
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

Re: random rows selection

2005-07-20 Thread Michael Monashev
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

Re: random rows selection

2005-07-20 Thread Chris Knipe
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

Re: random rows selection

2005-07-20 Thread Gleb Paharenko
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

random rows selection

2005-07-20 Thread Michael Monashev
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