mysql - Fetching a random record -
i developing ruby on rails question bank application.i want know how retrive random records database out duplication.and using mysql database.also random records show in view.
solution: 1
user.limit(10).order("rand()")
solution: 2
ids = user.pluck(:id).shuffle[0..9]
user.where(id: ids)
Comments
Post a Comment