[Gllug] Perl DBI question
Ryan Cartwright
ryan at crimperman.org
Mon Oct 2 22:09:52 UTC 2006
Adrian McMenamin wrote:
> Maybe more appropriate for a perl list...
>
> Given a database of N records where N > 0 but size of N is otherwise
> unkown, is it possible to pick a random record from the database?
>
> I cannot find any examples on google...
>
> Alternatively, any simple way (ie other than selecting every record and
> counting them) of determining N?
>
> Thanks
>
Isn't this just a case of using rand[om] within your SQL?
SELECT * FROM TABLE1 ORDER BY RAND() LIMIT 1; -- MySQL
SELECT * FROM TABLE1 ORDER BY RANDOM() LIMIT 1; -- PostgreSQL
Run that through your DBI calls and grab the result.
Of course I'm making the assumptions that you are using MySQL/PostgreSQL.
HTH
Ryan
--
Gllug mailing list - Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug
More information about the GLLUG
mailing list