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

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -