- or download this
my $limit = 1;
my $query = qq{SELECT id FROM table ORDER BY RAND() LIMIT $limit};
...
WHERE id in (}
. (join ",", @$ids)
. " ) " ;
- or download this
mysql> create table if not exists support_tbl
-> (cnt int not null auto_increment primary key,
-> id int not null);
mysql> truncate support_tbl;
mysql> insert into support_tbl (id) select id from table order by rand
+();
- or download this
my $cnt =1;
my $ids = $dbh->selectcol_arrayref(qq{select id from
support_tbl where cnt = ?}, undef, $cnt);
- or download this
# make sure our random value is not higher than
# any value in the primary key
...
my $cnt = rand($max);
my $query = qq{SELECT question, answer FROM table WHERE id = $cnt };