Solution to ORDER BY RAND()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Option 1 | |
SELECT * | |
FROM title t | |
WHERE kind_id = 1 AND id >= FLOOR(1 + RAND() * (SELECT MAX(id) FROM title)) LIMIT 1; | |
-- Option 2 | |
SELECT id, title | |
FROM title t RIGHT JOIN | |
(SELECT CEIL(RAND() * (SELECT MAX(id) FROM title WHERE kind_id = 1)) AS id) h USING (id); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment