Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
users という名前の Rails テーブルがあり、データベースからランダムなレコードを取得する最良の方法を知りたいので、通常のように取得するのと同じように高速になります
@users = User.all
ありがとう....
これを試して:
# Get 5 random users @users = User.order('RAND()').limit(5)
RAND()(MySQL) 関数はRANDOM()PostgreSQL と SQLiteで呼び出されることに注意してください。
RAND()
RANDOM()