Random row selection


How to select random record.

Table creation:

First variant is based on random ordering, which can be very slow on big tables:


Next variant generates random number that is used in WHERE clause to select the row:

This query works when table has no gaps in values.

Leave a Reply

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