problem with DBI.pm and ORDER BY RAND() in mysql

J

Joe Blower

When I execute the following SQL statement at the mysql> prompt, I get a
random result:

SELECT proxy FROM proxies WHERE active = 1 ORDER BY RAND() LIMIT 1;

When I wrap it in my perl code, I always get the first row in the database.

my $dbh = DBI->connect("dbi:mysql:$db:host=$db_host", $db_user, $db_pass);

my $sql = "SELECT proxy FROM proxies WHERE active = 1 ORDER BY RAND() LIMIT
1";
my $sth = $dbh->prepare($sql) or die $dbh->errstr;
$sth->execute() or die $dbh->errstr;
while (my $row = $sth->fetch())
{
$proxy = $row->[0];
}



Motiv8x
Top25Web.com: Ranking Report & Search Engine Forums
http://www.top25web.com
 
D

dw

Joe Blower said:
When I execute the following SQL statement at the mysql> prompt, I get a
random result:

SELECT proxy FROM proxies WHERE active = 1 ORDER BY RAND() LIMIT 1;

When I wrap it in my perl code, I always get the first row in the database.

my $dbh = DBI->connect("dbi:mysql:$db:host=$db_host", $db_user, $db_pass);

my $sql = "SELECT proxy FROM proxies WHERE active = 1 ORDER BY RAND() LIMIT
1";

How about removing the 'LIMIT 1"?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top