12 messages in com.mysql.lists.mysqlTrouble using RAND function| From | Sent On | Attachments |
|---|---|---|
| Darla Baker | 02 Oct 1999 17:21 | |
| Jani Tolonen | 03 Oct 1999 05:10 | |
| Darla Baker | 03 Oct 1999 08:56 | .txt |
| Stan P. van de Burgt | 03 Oct 1999 09:11 | |
| Jani Tolonen | 03 Oct 1999 09:22 | |
| Darla Baker | 03 Oct 1999 10:15 | |
| Martin Ramsch | 03 Oct 1999 12:43 | |
| Darla Baker | 03 Oct 1999 14:38 | |
| Jani Tolonen | 03 Oct 1999 17:55 | |
| Darla Baker | 04 Oct 1999 03:15 | |
| Matthias Urlichs | 04 Oct 1999 04:07 | |
| Michael Widenius | 06 Oct 1999 06:35 |
| Subject: | Trouble using RAND function![]() |
|---|---|
| From: | Jani Tolonen (ja...@mysql.com) |
| Date: | 10/03/1999 05:10:43 AM |
| List: | com.mysql.lists.mysql |
Darla Baker writes:
I am trying to write a perl script that I will link to a graphic on my web page so that when the graphic is clicked it will take the user to a random favorite from my collection of favorite urls. I've been testing the SELECT statement from the mysql command line using the following statement:
SELECT _rowid,url from favorites WHERE _rowid = ROUND( (RAND()*24) + 1 );
Right now there are 25 entries in the table and _rowid is an auto_increment field. When I execute the query I get an empty set frequently and then occasionally it will return a row. What am I missing? I am running mysql 3.22.22
Darla Baker dar...@metrodayton.net
Hi Darla,
The above should work. Can you please include in the mail the output from the following:
shell> mysqldump db_name favorites
Please show us also some output from the client when you execute queries:
mysql> SELECT ROUND((RAND() * 24) + 1);
and
mysql> SELECT RAND();
couple of times.
Here is an alternative query you can try, for the meanwhile we try to find out why the above doesn't work:
SELECT _rowid,url FROM favorites WHERE _rowid = (((RAND() * 24) % 24) + 1);
Regards,
- Jani
-- +-------------------------------------------------------------+ | TcX ____ __ _____ _____ ___ | | /*/\*\/\*\ /*/ \*\ /*/ \*\ |*| Jani Tolonen | | /*/ /*/ /*/ \*\_ |*| |*||*| ja...@mysql.com | | /*/ /*/ /*/\*\/*/ \*\|*| |*||*| Helsinki | | /*/ /*/ /*/\*\_/*/ \*\_/*/ |*|_____ Finland | | ^^^^^^^^^^^^/*/^^^^^^^^^^^\*\^^^^^^^^^^^ | | /*/ \*\ Developers Team | +-------------------------------------------------------------+





.txt