Hi
When I used the RAND() function (MySQL 3.23.45) I found the results were not
very random, instead I use an extra bit of php code to make sure the results
are more random.
mt_srand((double)microtime()*100);
$sql = select order by RAND(.mt_rand(0,32767).) limit 50
$rs = mysql_query
At 11:32 -0400 5/7/02, Cummings, Shawn (GNAPs) wrote:
The RAND() syntax does not appear to be working for me.
What version mySQL is required?
3.23.2. Prior to that, use
SELECT something, any_col*0+RAND() AS r FROM sometable
WHERE ... ORDER BY r LIMIT 10
At 04:43 PM 1/29/2002 +0200, Michael
Quoted from the manual page I have given below is:
RAND() is not meant to be a perfect random generator, but instead a fast
way to generate ad hoc random numbers that will be portable between
platforms for the same MySQL version.
So it was intentionally built so...
Gurhan
-Original
Hi,
I am trying the below sql statment:
mysql select c.city, t.periodo, t.vitofferta from travel t, city c where
t.cityid=c.id and t.periodo2001-07-20 and
month(t.periodo)=month(2001-07-20) and
YEAR(t.periodo)=YEAR(2001-07-20) and rand() limit 7;
The result
- Original Message -
From: Derick Dorner
To: [EMAIL PROTECTED]
Sent: Tuesday, July 17, 2001 3:11 PM
Subject: tricky RAND() function...
I am using MySQL 3.22, and need to know how to randomly select a record, therefore I
can't just use the ORDER BY RAND() clause, because of my
From the German php FAQ:
version = 3.23
SELECT * FROM tabelle ORDER BY RAND() LIMIT 1
version 3.23
//see how many rows you have
$result = @mysql_query(SELECT COUNT(*) FROM $table);
$row = mysql_fetch_row($result);
//produce random number out of that
mt_srand((double)microtime()*100
From the German php FAQ:
version = 3.23
SELECT * FROM tabelle ORDER BY RAND() LIMIT 1
version 3.23
//see how many rows you have
$result = @mysql_query(SELECT COUNT(*) FROM $table);
$row = mysql_fetch_row($result);
//produce random number out of that
mt_srand((double)microtime()*100
I am using MySQL 3.22, and need to know how to randomly select a record, therefore I
can't just use the ORDER BY RAND() clause, because of my version. so i do this:
SELECT field1,field2*0+RAND() as rand_col FROM TableName WHERE field3=5 ORDER BY
rand_col;
--according to paul dubois' book I have
Hi all, trying to do something and have it be as efficient as possilble. My
question is if I have a table with say 10,000 rows in it, and I issue
a command like this
select * from table where number=1 order by rand() limit 1;
If 1000 rows would match this command does mysql first find all
)));
for ($foo=1; $foo=1; $foo++) {
$s = INSERT INTO mytable SET myfield=. $foo;
mysql_query($s);
}
?
end
produces a table with 1 rows each containing an integer. Then we do:
mysql SELECT * FROM mytable ORDER BY RAND() LIMIT 5;
+-+
| myfield
by rand() limit 1;
If 1000 rows would match this command does mysql first find all 1000 rows
and THEN randomly select 1 of those to return, OR does it just randomly
start somewhere and then stop when it finds one? The first method would
be really slow and inefficient, but I am afraid
I don't think the answer has changed since last week :-)
IMHO it's not really slow and inefficient, anyway - this script:
(clipped)
produces a table with 1 rows each containing an integer. Then we do:
mysql SELECT * FROM mytable ORDER BY RAND() LIMIT 5;
(clipped)
5 rows in set (0.08
In a slight change of this question (since I have no data to currently test
this with, as my ISP is using too old a version of mysql), does anyone know
what something like this would do?
SELECT * FROM theTable ORDER BY RAND(), date LIMIT 5;
I'd like to be able to pull out a certain number
In a slight change of this question (since I have no data to
currently test this with, as my ISP is using too old a
version of mysql), does anyone know what something like
this would do?
SELECT * FROM theTable ORDER BY RAND(), date LIMIT 5;
Exactly the same as SELECT * FROM theTable ORDER
BY
RAND() LIMIT 5;
SELECT * FROM temptable ORDER BY date;
DROP TABLE temptable;
-
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request
In a slight change of this question (since I have no data to
currently test this with, as my ISP is using too old a
version of mysql), does anyone know what something like
this would do?
SELECT * FROM theTable ORDER BY RAND(), date LIMIT 5;
Exactly the same as SELECT * FROM theTable
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
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
SELECT something FROM users WHERE statement_ok = 1 ORDER BY RAND() LIMIT 0,
1
When I use the above SQL I mostly get the same result. How can I prevent
that ?
:) Jacob
--
[ www.eksperten.dk ] Scandinavias biggest IT forum
Hi~
I have inserted 1,000,000 record into table.
and selected 1 record using order by rand().
but, it was very very slow.
mysql explain member ;
+---+--+--+-+-++
| Field | Type | Null | Key | Default | Extra
i just think you're lucky to get a row each time. your query returnes an
undefined number of rows.
Each row.numberhed against rand(), so sometimes a row matches, sometimes
not. rand() is not a constant, but calculated each match!
maybe you're looking for a query like:
select bid, number, title
[EMAIL PROTECTED] writes:
Description:
The documentation says that I can do:
select * from table order by rand() limit 10
as an example, however it fails and there is no error message.
I *can* do:
select * from table order by rand()
which works fine. It just seems that adding
Description:
The documentation says that I can do:
select * from table order by rand() limit 10
as an example, however it fails and there is no error message.
I *can* do:
select * from table order by rand()
which works fine. It just seems that adding the limit clause causes
something to break
SELECT * from tablename ORDER BY RAND()
does not work in 3.22.25 what is the equivalent ??
It works great in later versions
chris
_
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
ows, where M is a pretty lightweight
access to nab the key. The "LIMIT $rand, 1" approach is O(D*n/2) on the
number of rows over time, but D is a nasty I/O hit to slurp the whole row
into the resultset.
The only case where Carsten's approach and mine would converge would be if
yo
Could you do something like:
CREATE TEMPORARY TABLE temptable (
pk INTEGER,
rand INTEGER
);
INSERT INTO temptable SELECT yourpk,Rand() FROM yourtable;
SELECT yourtable.* FROM yourtable,temptable WHERE pk=yourpk ORDER BY rand;
DROP TABLE temptable;
That might be quicker than your current
Hi there,
In the quest to get a random row from a table, "order by rand()" has
proven too inefficient and slow. It's slow because MySQL apparently
selects ALL rows into memory, then randomly shuffles ALL of them, then
gives you the first one - very inefficient. There are a few
?php
$query = "SELECT col1, col2 FROM the_table ORDER BY RAND() LIMIT 1";
$result = mysql_query($query) or die("could not query");
$row = mysql_fetch_array($result);
print $row[col1];
print "P";
print $row[col2];
?
Robert B. Barrington
GetMart Commercia
"Jeffrey D. Wheelhouse" wrote:
SELECT @lines:=COUNT(id) FROM table;
SET @rand=CEILING(RAND()*@lines);
SELECT * FROM table WHERE (@rand:=@rand-1)+id=id;
Never mind on the "it doesn't work on my system" more like it didn't
work on my brain :) Works fine. And now th
101 - 129 of 129 matches
Mail list logo