MySQL Random query data
Previously discussed this problem in the group, the comparison is interesting. MYSQLL's grammar is really fun. They all want to use PHP to achieve random, but take out more than two times as if to do more than a query. Turn the manual, find the following statement, you can complete the task.
Copy Code code as follows:
SELECT * FROM table_name ORDER BY RAND () LIMIT 5;
The rand () function of MySQL says so in the manual:
RAND () rand (N)
Returns a random floating-point value in the range 0 through 1.0. If an integer parameter n is specified, it is used as a seed value.
For the efficiency of MySQL's rand () function, you can refer to the MYSQLL Order by Rand () Efficiency: http://www.phpq.net/MySQLl/MySQLl-order-by-rand.html
Actual effect
Copy Code code as follows:
Mysqll> select RAND ();
-> 0.5925
Mysqll> Select RAND (20);
-> 0.1811
Mysqll> Select RAND (20);
-> 0.1811
Mysqll> select RAND ();
-> 0.2079
Mysqll> select RAND ();
-> 0.7888
mysql random update data
How to write a statement can update hundreds of MYSQLL data!
Need to test the MySQL database, which has a database of tens of thousands of data, how to write a PHP file every time update hundreds of information, I am writing a cycle to update a message, so I know with a while to write on it, if an update like 100 data changes how to write it?
The correct answer is:
Copy Code code as follows:
UPDATE cdb_posts SET views = rand ();
The gas is dead. In the Insert command, the value () is in rand (), note that the field width is enough to always think MySQL randomly query a few data, use
Copy Code code as follows:
SELECT * from ' table ' ORDER by RAND () LIMIT 5
On it, the above related content is to MYSQLL random query data, MySQL random update data. The introduction, hope you can have some gains.