Sagewire Logo

Selecting a random row

2 Message(s) by 2 Author(s) originally posted in mysql discussion


From: laredotornado Date:   Wednesday, October 24, 2007
Hi,

I'm using MySQL 5.0 and have InnoDB tables. How do I select a random,
single row of data from a given table, "T"?

Thanks, - Dave


From: Captain Paralytic Date:   Thursday, October 25, 2007
On 24 Oct, 23:36, "laredotorn...@xxxxxxxxxxx"
wrote in message:
Hi,
I'm using MySQL 5.0 and have InnoDB tables. How do I select a random,
single row of data from a given table, "T"?
Thanks, - Dave



It is a 3 step process:

1) You use Google to search this group for the word "random"
2) You read a couple of the posts there that explain how to do it
3) You do it



Next Message: UNIQUE constraint and RAND() function?


Blogs related to Selecting a random row

PHP And MySQL Interview Questions
-d, –no-data Don’t write any row information for the table. This is very useful if you just want to get a dump of the structure for a table! Q:41 How can we optimize or increase the speed of a MySQL select ...

Tip: Selecting random row with MySQL and ActiveRecord
Here's a quick tip on how to select a random model instance from an ActiveRecord model when the database is MySQL: Model.find(:first, :order => 'rand()', :limit => 1) Please note:. Using rand() is MySQL specific; It performs bad when ...

MySQL Reference
The first row is number (eg, SELECT url FROM links LIMIT 5,10 returns URLs numbered 5 through 14). PROCEDURE name ([ arg_list]). In early versions of MySQL, this does not do anything. It was provided to make importing data from other ...

selected scenes in macbeth
... selecting process selecting projects selecting quality tool selecting quality tools selecting quilt fabric selecting radio buttons selecting ram selecting random records selecting random records from database selecting random rows ...

Random Timestamps in MySQL
Have you ever needed a random timestamp in MySQL? For example to create demo data programmatically? Here’s my solution: SELECT FROM_UNIXTIME( FLOOR( UNIX_TIMESTAMP('2007-01-01') + RAND() ...

Selecting a Random Row from a MySQL Table
In order to ensure that I could select a random lyric with every page request, I needed to be able to select a random row from a lyrics table in my database. To accomplish this, I first needed to get a count of all the lyrics currently ...


Programming | Sports | Autos

copyright 2006
Valid XHTML 1.0 Transitional