Help for this page

Select Code to Download


  1. or download this
    my $limit = 1;
    my $query = qq{SELECT id FROM table ORDER BY RAND() LIMIT $limit};
    ...
        WHERE id in (}
        . (join ",", @$ids)
        . " ) " ;
    
  2. 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
    +();
    
  3. or download this
    my $cnt =1;
    my $ids = $dbh->selectcol_arrayref(qq{select id from 
        support_tbl where cnt = ?}, undef, $cnt);
    
  4. 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 };