• notice
  • Congratulations on the launch of the Sought Tech site

MySQL random query data with random update data implementation code

MySQL Random Query Data
I have discussed this issue in the group before, and it is quite interesting.The syntax of MySQLl is really fun.They all wanted to use PHP is random, but it seems that more than two queries are required to take out multiple pieces.I looked through the manual and found the following sentence to complete the task.
The code is as follows:

SELECT * FROM table_name ORDER BY rand() LIMIT 5;

MySQL's rand() function says this in the manual:
RAND() RAND(N)
Returns a random floating point value in the range 0 to 1.0.If an integer parameter N is specified, it is used as the seed value.
For the efficiency of MySQL's rand() function, you can refer to "MySQLL Order By Rand() Efficiency": http://www.phpq.net/MySQLl/MySQLl-order-by-rand.html
The actual effect
The code is 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 updates data randomly
How to write a statement Update hundreds of MySQLL data at once!
You need to test the MySQL database, there is a database with tens of thousands of data, how to write a PHP file Every time I update a few hundred pieces of information, I always write a loop to update one piece of information at a time, so I know that it is enough to write with WHILE.If one update is like 100 pieces of data, how to write it?
The correct answer is:
The code is as follows:

UPDATE cdb_posts SET views=rand();

In the insert command, use rand() in the value().Pay attention to whether the field width is enough.Always think that MySQL queries several data randomly, just use
The code is as follows:

SELECT * FROM `table` ORDER BY RAND() LIMIT 5

Just Yes, the above related content is to query data randomly for MySQLL and update data randomly for MySQL.I hope you can gain something from the introduction.

Tags

Technical otaku

Sought technology together

Related Topic

1 Comments

author

buy lipitor 80mg without preion & lt;a href="https://lipiws.top/"& gt;atorvastatin 40mg cost& lt;/a& gt; lipitor pills

Nwmdjj

2024-03-10

Leave a Reply

+