qb icon indicating copy to clipboard operation
qb copied to clipboard

[Improvement] Add Ability to Order Query Results Randomly

Open homestar9 opened this issue 1 year ago • 3 comments

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/

homestar9 avatar Jan 26 '24 18:01 homestar9