The following article mainly introduces the MySQL random selection of data, the implementation of MYSQ random query data and MYSQ random update data of the actual operation of the description, and the actual operation of the statement to be used in the description, the following is a description of its specific operation steps.
MySQL Random query data
I used to discuss this problem in the group. MySQL's syntax is fun. They used to want to use PHP to implement random, but take out more than two times like to make more than one query. Turn the manual, find the following statement, you can complete the task.
SELECT * from ORDER by Rand 5
The rand () function in MySQL says so in the manual:
RAND () RAND
Returns a random floating-point value within a range of 0 to 1.0. If an integer parameter n is specified, it is used as the seed value.
For the efficiency of the rand () function in MySQL, 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.5925MySQL> Select RAND( -); - 0.1811MySQL> Select RAND( -); - 0.1811MySQL> Select RAND(); - 0.2079MySQL> Select RAND(); - 0.7888
MySQL Random update data
How to write a statement can update hundreds of MySQL data!
Need to test MySQL database, there is a database of tens of thousands of data, how to write a PHP file every time the update hundreds of information, I am writing a loop to update a message, so I know with while write can be, if a
Update is like 100 data changes how to write it?
The correct answer is:
UPDATE SET = Rand ();
Air dead in the Insert command, value () inside with Rand (), notice that the field width is enough to always think that MySQL randomly query a few data, use
SELECT * from 'tableORDERbyRAND5
You can do it. The above related content is to implement MYSQ random query data, MYSQ random update data Introduction, hope you can have some gains.
How to implement MySQL random query data with MySQL random update data?