How do you get random records from a table? This interview question never gets old. Here is the ORDER BY method I use because its syntax is easy to remember.
MySQL – How to Generate Random Number
MySQL’s UUID() function returns a random 36 character value. Here is how to generate random number strings and passwords of any length from it.
SQL SERVER – Generate Different Random Number for Each Group Using RAND() Function
The RAND() function returns the same value for every row in a query. Here is a simple trick to generate a different random number for each group.
TABLESAMPLE Samples Pages, Not Rows: Sampling a Large Table Right
Compare TABLESAMPLE page sampling with NEWID sorting and CHECKSUM filters by row count, reads, spread, and repeatability.
Generating Random Numbers Per Row: RAND, NEWID and CRYPT_GEN_RANDOM
Generate random numbers per row with NEWID or CRYPT_GEN_RANDOM, compare seeded RAND, inspect bucket spread, and pick a row without a sort.
Picking Random Winners Fairly With NEWID and CRYPT_GEN_RANDOM
Pick random winners with NEWID or cryptographic randomness, handle weights and unique entrants, and save a draw with its seed and timestamp.
SQL SERVER – Generate A Single Random Number for Range of Rows of Any Table – Very interesting Question from Reader
A reader asked how to get a single random number for a set of rows, like one per PostalCode. I compare NEWID() for each row with RAND() for a whole set.







