Categories
Quick Tips Snippets SQL

Generating Random Numbers in SQL

To generate random integers from min to max, including min and max

SELECT FLOOR( RAND()*( Max - Min + 1 )) + Min;

Example: To create a random integer between 5 and 10

SELECT FLOOR( RAND()*( 10 - 5 + 1 )) + 5;

Leave a Reply