MemoryRefresh!

Query / Order by rand     Order by rand



Questions Answers 0%

Pages   0 from 12
Questions   0 from 14

Reset


Order by rand (very slow)
SELECT * FROM article ORDER BY RAND() LIMIT 1; Order by rand (quick)
ALTER TABLE article ADD random FLOAT NOT NULL, ALTER TABLE ADD INDEX random (random); UPDATE article SET random = RAND(); INSERT INTO article (..., random) VALUES (..., RAND()); SELECT * FROM article WHERE random > (SELECT RAND() as rand) ORDER BY random LIMIT 1; Order by array
SELECT * FROM documents WHERE id IN (3, 7, 5) ORDER BY FIELD (id, 3, 7, 5) electrictoolbox.com stackoverflow.com dev.mysql.com

Related Pages

Order by rand
Concat fields
Select search
Regexp
If null
Union


0% 100%
 
 
0 pages 12 pages
1) Is it best practice to order by RAND()?




2) How do you order by array?







Order by rand (very slow)
SELECT * FROM article ORDER BY RAND() LIMIT 1; Order by rand (quick)
ALTER TABLE article ADD random FLOAT NOT NULL, ALTER TABLE ADD INDEX random (random); UPDATE article SET random = RAND(); INSERT INTO article (..., random) VALUES (..., RAND()); SELECT * FROM article WHERE random > (SELECT RAND() as rand) ORDER BY random LIMIT 1; Order by array
SELECT * FROM documents WHERE id IN (3, 7, 5) ORDER BY FIELD (id, 3, 7, 5) electrictoolbox.com stackoverflow.com dev.mysql.com





Programming

Php
   
Regex
   
MySQL
   
Css
   
jQuery
   
Git
   


References
n/a