How can I use this query the rails way? $query = "SELECT * FROM images ORDER BY RAND() LIMIT 16"; -- Jochen
> 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
Reasonably Related Threads
- editor recommendation
- RoR logo on own webpage
- the word "rand" comes up in console after typing a command
- Building R package: “Found 'rand', possibly from 'rand' (C)” NOTE when checking package
- [LLVMdev] Use rand_r() instead of non-reentrant thread-unsafe rand() in GetRandomNumber()