content_image/862842.jpg content_image/862843.jpg content_image/862844.jpg
<img src='content_image/862842.jpg'>

3 rows in set (0.00 sec) 

mysql> SELECT i, RAND() FROM t; 

<img src='content_image/862843.jpg'>

3 rows in set (0.00 sec) 

mysql> SELECT i, RAND(3) FROM t; 

<img src='content_image/862844.jpg'>

3 rows in set (0.01 sec) 

RAND()  in a WHERE  clause is evaluated for every row (when selecting from one table) or combination of rows (when selecting from a multiple-table join). Thus, for optimizer purposes, RAND()  is not a constant value and cannot be used for index optimizations. For more information, see Section 8.2.1.20, “Function Call Optimization” . 

Use of a column with RAND()  values in an ORDER BY  or GROUP BY  clause may yield unexpected results because for either clause a RAND()  expression can be evaluated multiple times for the same row, each time returning a different result. If the goal is to retrieve rows in random order, you can use a statement like this: 

SELECT * FROM tbl_name  ORDER BY RAND(); 

To select a random sample from a set of rows, combine ORDER BY RAND()  with LIMIT : 

SELECT * FROM table1, table2 WHERE a=b AND c<d ORDER BY RAND() LIMIT 1000; 

RAND()  is not meant to be a perfect random generator. It is a fast way to generate random numbers on demand that is portable between platforms for the same MySQL version. 

This function is unsafe for statement-based replication. A warning is logged if you use this function when binlog_format  is set to STATEMENT . 

## • ROUND( X ) , ROUND( X , D ) 

Rounds the argument X  to D  decimal places. The rounding algorithm depends on the data type of X . D defaults to 0 if not specified. D  can be negative to cause D  digits left of the decimal point of the value X  to become zero. The maximum absolute value for D  is 30; any digits in excess of 30 (or -30) are truncated. 

mysql> SELECT ROUND(-1.23); -> -1 mysql> SELECT ROUND(-1.58); -> -2 mysql> SELECT ROUND(1.58); -> 2 

