Here’s a quiz, which of the following would be more efficient and take less time to perform?
SQL Query 1
SELECT * FROM products WHERE id >= RAND() * (SELECT MAX(id) FROM products) LIMIT 20
SQL Query 2
SELECT * FROM products ORDER BY RAND() LIMIT 20
I’ve published the results here (tested on MySQL). 2 runs were conducted and they both proved that the first SQL query was more efficient.
Comments welcomed.
Leave a Reply