Random record retrieval from database

Discussion in 'Ruby' started by Subashini Kumar, Sep 23, 2009.

  1. How can i choose some "n" (n is gonna be fixed )records randomly from a
    mysql database table from our controller?
    --
    Posted via http://www.ruby-forum.com/.
    Subashini Kumar, Sep 23, 2009
    #1
    1. Advertising

  2. Hi,

    > How can i choose some "n" (n is gonna be fixed )records randomly from
    > a mysql database table from our controller?


    What I usually do is compute a column using a random function (mysql
    has one) and then order by that column. You can use LIMIT to only
    retrieve some results.

    This is going to be CPU/Disk intensive if your table is very large.

    kaspar
    Kaspar Schiess, Sep 23, 2009
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sparky Arbuckle

    Access Database Value Retrieval

    Sparky Arbuckle, Jun 3, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    353
    =?Utf-8?B?QmhhdmVzaCBQYXRlbA==?=
    Jun 3, 2005
  2. globalrev
    Replies:
    4
    Views:
    742
    Gabriel Genellina
    Apr 20, 2008
  3. ArtySin

    textbox retrieval from sql server database

    ArtySin, Dec 2, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    679
    ArtySin
    Dec 2, 2006
  4. Jimmy
    Replies:
    27
    Views:
    303
    Mike Brind
    Sep 8, 2006
  5. VK
    Replies:
    15
    Views:
    1,116
    Dr J R Stockton
    May 2, 2010
Loading...

Share This Page