ORDER BY RAND() combined with LIMIT is useful for selecting a random sample of a set of rows:

SELECT * FROM <tablename> ORDER BY RAND() LIMIT 1000;

Note that RAND() in a WHERE clause is re-evaluated every time the WHERE is executed. So be careful using this is you have a large table with a lot of rows in it or a high traffic site as it can take a lot of resources to run it.

How to select a random set of records using MySQL
Tagged on:

Leave a Reply

Your email address will not be published. Required fields are marked *

− one = 1