Timeline for How to request a random row in SQL?
Current License: CC BY-SA 2.5
3 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Sep 21, 2014 at 5:05 | comment | added | Andres Riofrio | As far as I can tell this does not run in constant time, it runs in linear time. In the worst case, @n is equal to the number of rows in the table, and "SELECT * FROM table LIMIT ?,1" evaluates @n - 1 rows until it gets to the last one. | |
Feb 8, 2011 at 22:33 | comment | added | guido | This solution also takes care of returning random rows when the indexed numeric value used in the where clause above is not equally distributed; so even if it takes almost the same (constant) time as using where id_value >= RAND() * MAX(id_value), it's better. | |
Jan 9, 2011 at 6:49 | history | answered | ldrut | CC BY-SA 2.5 |