MySQL RAND function is one of the Mathematical Function which is used to return or generate the random numbers between 0 and 1.
In this article, we will show you, How to get random values in MySQL using Command Prompt, and Workbench with examples.
MySQL RAND Syntax
The syntax of the RAND in MySQL is as shown below:
Generally, this function generate numbers between 0.0 to 1.0. However, if you want a random integer then you have to follow below technique.
SELECT FLOOR(10 + RAND() * 30);
This generates the random integer number between 10 and 30.
MySQL RAND Function Example 1
The MySQL Random Function is used to return the random values. The following query will show multiple ways to use RAND function.
SELECT RAND(10), RAND(120), RAND(-150);
MySQL RAND Example 2
The MySQL RAND Function also allows you to return or store random values inside a column.
In this example, we are generating random numbers for each employee in a customer table.
FROM `MySQL Tutorial`.customer;
Thank You for Visiting Our Blog