How can I use this query the rails way?
$query = “SELECT * FROM images ORDER BY RAND() LIMIT 16”;
How can I use this query the rails way?
$query = “SELECT * FROM images ORDER BY RAND() LIMIT 16”;
How can I use this query the rails way?
$query = “SELECT * FROM images ORDER BY RAND() LIMIT 16”;
Image.find(:all, :order => ‘RAND()’, :limit => 16)
Just keep in mind that if there are a million rows in that table mysql
is
going to look at them all, add a RAND() column, sort it, then return the
first 16.
Which could get expensive db-wise…
-philip
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs