Home > database >  A random access database data, with the WHERE condition
A random access database data, with the WHERE condition

Time:10-23

The following link is to find information, to the didn't add the where query condition! https://blog.csdn.net/c_staunch/article/details/84428904 SELECT * FROM table_name as t1 WHERE t1. Id>=RAND () * (SELECT MAX (id) FROM table_name)) LIMIT 1;
This statement is how to add the where condition, tried many times are not

CodePudding user response:

Efficiency of a way:
Select * from table_name
The where condition
The order by the rand () limit 1

CodePudding user response:

A good efficiency:
 select * from table_name where col1=XXX 
And id>=rand () * (SELECT Max (id) FROM table_name WHERE col1=XXX) limit 1;

Remember the query condition index,

CodePudding user response:

Have a look at this, it is estimated that can help you,
https://blog.csdn.net/AHUA1001/article/details/103126626

CodePudding user response:

refer to the original poster don't ask, don't return _ response:
link below is to find information, to this didn't add the where query condition! https://blog.csdn.net/c_staunch/article/details/84428904 SELECT * FROM table_name as t1 WHERE t1. Id>=RAND () * (SELECT MAX (id) FROM table_name)) LIMIT 1;
This statement is how to add the where condition, tried many times can't

Your script using the default sorting, so every time should be returned to the same record, add a sequenced:
 SELECT * FROM table_name as t1 
WHERE a t1. Id>=RAND () * (SELECT MAX (id)
The FROM table_name))
The ORDER BY t1. Id
LIMIT 1;


If the t1. The order of the id is not starting from 1 (such as id for the incremental, but deleted too many data, cause id "empty"), consider using id interval random:
 SELECT * FROM table_name as t1 
WHERE a t1. Id>=(SELECT RAND () * (MAX (id) - MIN (id)) + MIN (id)
The FROM table_name)
The ORDER BY t1. Id
LIMIT 1;

CodePudding user response:

reference 4 floor kampoo response:
Quote: refer to the original poster don't ask, don't return _ response:

The following link is to find information, to the didn't add the where query condition! https://blog.csdn.net/c_staunch/article/details/84428904 SELECT * FROM table_name as t1 WHERE t1. Id>=RAND () * (SELECT MAX (id) FROM table_name)) LIMIT 1;
This statement is how to add the where condition, tried many times can't

Your script using the default sorting, so every time should be returned to the same record, add a sequenced:
 SELECT * FROM table_name as t1 
WHERE a t1. Id>=RAND () * (SELECT MAX (id)
The FROM table_name))
The ORDER BY t1. Id
LIMIT 1;


If the t1. The order of the id is not starting from 1 (such as id for the incremental, but deleted too many data, cause id "empty"), consider using id interval random:
 SELECT * FROM table_name as t1 
WHERE a t1. Id>=(SELECT RAND () * (MAX (id) - MIN (id)) + MIN (id)
The FROM table_name)
The ORDER BY t1. Id
LIMIT 1;
thank you

CodePudding user response:

reference AHUA1001 reply: 3/f
look at this, estimates that can help you,
https://blog.csdn.net/AHUA1001/article/details/103126626
thank you

CodePudding user response:

refer to the second floor Dong Xuyang TonyDong response:
efficiency good a way:
 select * from table_name where col1=XXX 
And id>=rand () * (SELECT Max (id) FROM table_name WHERE col1=XXX) limit 1;

Remember to add index, query condition
thank you
  • Related