qb
qb copied to clipboard
[Improvement] Add Ability to Order Query Results Randomly
It would be valuable to have a method in QB to return a random row from the query. Perhaps we could have an orderByRandom()
method.
Examples:
// return a random record from the product table
qb.from( 'product' ).orderByRandom().first();
// return 5 random records from the product table (note there currently isn't a `limit` option in QB
qb.from( 'product' ).orderByRandom().simplePaginate( 1, 5 );
Different implementations of random: https://www.petefreitag.com/blog/sql-select-random-row/