ExpertRefresh

Order by rand

Query

Order by rand
Concat fields
Select search
Regexp
If null
Union
Using syntax


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




2) How do you order by rand daily?







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; Daily rand SELECT * FROM article ORDER BY rand("20190131") # date(Ymd) Order by array SELECT * FROM documents WHERE id IN (3, 7, 5) ORDER BY FIELD (id, 3, 7, 5)