This month's discount Comprehensive Database Performance Health Check · Testimonials
SQLAuthority with Pinal Dave
Home
  • Consulting
    • Health Check
  • Free Videos
  • All Articles
    • AI
    • SQL Performance
    • SQL Tips and Tricks
    • Interview Questions and Answers
    • SQL Puzzle
    • SQL Video
    • SQLAuthority News
    • Personal
  • Books
  • Consulting
Unmarked tokens tumble from a wooden raffle drum

How to Get Random Records from Table? – Interview Question of the Week #105

January 8, 2017
Pinal Dave
SQL Interview Questions and Answers
SQL Function, SQL Random, SQL Scripts, SQL Server

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.

Read More
MySQL - How to Generate Random Number

MySQL – How to Generate Random Number

February 6, 2016
Pinal Dave
SQL Tips and Tricks
MySQL, SQL Random

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.

Read More
SQL SERVER - Generate Different Random Number for Each Group Using RAND() Function

SQL SERVER – Generate Different Random Number for Each Group Using RAND() Function

April 25, 2015
Pinal Dave
SQL Tips and Tricks
SQL Function, SQL Random

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.

Read More
A glass vase of beans in colored layers, a scoop from the top holding only red beans.

TABLESAMPLE Samples Pages, Not Rows: Sampling a Large Table Right

June 1, 2013
Pinal Dave
SQL Tips and Tricks
SQL Random, SQL Scripts, SQL Server

Compare TABLESAMPLE page sampling with NEWID sorting and CHECKSUM filters by row count, reads, spread, and repeatability.

Read More
Two rows of tulips, one all red and one in randomly mixed colors.

Generating Random Numbers Per Row: RAND, NEWID and CRYPT_GEN_RANDOM

February 2, 2013
Pinal Dave
SQL Tips and Tricks
Mathematical Function, SQL Function, SQL Random, SQL Server

Generate random numbers per row with NEWID or CRYPT_GEN_RANDOM, compare seeded RAND, inspect bucket spread, and pick a row without a sort.

Read More
A hand holding a bunch of grass stems by a campfire, one short stem with a red tip just drawn out

Picking Random Winners Fairly With NEWID and CRYPT_GEN_RANDOM

December 14, 2012
Pinal Dave
SQL Tips and Tricks
SQL Function, SQL Random, SQL Server, SQL Transactions

Pick random winners with NEWID or cryptographic randomness, handle weights and unique entrants, and save a draw with its seed and timestamp.

Read More
SQL SERVER - Generate A Single Random Number for Range of Rows of Any Table - Very interesting Question from Reader

SQL SERVER – Generate A Single Random Number for Range of Rows of Any Table – Very interesting Question from Reader

January 28, 2009
Pinal Dave
SQL Tips and Tricks
SQL Function, SQL Random, SQL Scripts

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.

Read More
Previous 1 2 3 Next
  • Books
  • Testimonials
  • Privacy Policy

© 2006 – 2026 All rights reserved. pinal @ SQLAuthority.com