Jump to: navigation, search

Mysql RAND

From w3cyberlearnings

Contents

PHP function RAND

This function returns a random number in a range v < 1 or v >= 0. When a seed value is specified,

Syntax RAND

V is an optional value and it uses to specify the seed number for the random function.

RAND(V)

Example 1


mysql> SELECT RAND();
+-------------------+
| RAND()            |
+-------------------+
| 0.196674733605864 | 
+-------------------+
1 row in set (0.00 sec)


Example 2

mysql> SELECT RAND(2);
+-------------------+
| RAND(2)           |
+-------------------+
| 0.655586646549019 | 
+-------------------+
1 row in set (0.00 sec)

Example 3

To generate a random order

mysql> SELECT * FROM tbl_name ORDER BY RAND();

OR

mysql> SELECT * FROM tbl_name ORDER BY RAND() LIMIT 100;

Related Links


Navigation
Web
SQL
MISC
References