Of course, the last part of my code is wrong. It is not a real random data fetch. Back home, hurry up to Baidu, so that we know how to randomly retrieve data ..
The rest of the code is not mentioned. Here we will show you the core data table search code:
The Code is as follows: |
|
Select * from table name order by rand () limit 1; // here, 1 is the number of retrieved data records |
But how can we improve the efficiency of data retrieval on the Internet?
Search for Google. Basically, data is randomly obtained by querying max (id) * rand () on the Internet.
The Code is as follows: |
|
SELECT * FROM 'table' AS t1 JOIN (select round (RAND () * (select max (id) FROM 'table') AS id) AS t2 WHERE t1.id> = t2.id Order by t1.id asc limit 5; |
However, five consecutive records are obtained. The solution can only be one query at a time and five queries at a time, but this does not meet my requirements. I need to find several
Efficient writing
The Code is as follows: |
|
SELECT * FROM user WHERE userId> = (select max (userId) FROM user)-(select min (userId) FROM user) * RAND () + (select min (userId) FROM user) LIMIT 5 |