Random record retrieval from database

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

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs