Tip: Selecting random row with MySQL and ActiveRecord
Model.find(:first, :order => 'rand()', :limit => 1)
Please note:
- Using rand() is MySQL specific
- It performs bad when there are many rows in table (rand() is applied to all rows and then all rows are sorted)



0 kommentarer:
Post a Comment