MYSQ Random Query data
Previously discussed this issue in the group, the comparison is interesting. MySQL's syntax is really fun. They all want to use PHP to implement the 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.
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 MySQL order by Rand () Efficiency: http://www.phpq.net/mysql/mysql-order-by-rand.html
Actual effect
mysql> select RAND();
-> 0.5925
mysql> select RAND(20);
-> 0.1811
mysql> select RAND(20);
-> 0.1811
mysql> select RAND();
-> 0.2079
mysql> select RAND();
-> 0.7888
MYSQ Random Update data
How to write a statement to update hundreds of MySQL 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: 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
SELECT * FROM `table` ORDER BY RAND() LIMIT 5
It's OK.