Antipattern: Sort Data Randomly

Let's see the techniques used to sort the data that causes an antipattern.

We'll cover the following...

The most common SQL trick to pick a random row from a query is to sort the query randomly and pick the first row. This technique is easy to understand and easy to implement:

Press + to interact
SELECT * FROM Bugs ORDER BY RAND() LIMIT 1;

Although this is a popular solution, it quickly shows its weakness. To understand this weakness, let’s first compare it to conventional sorting, in which we compare values in a column and order the rows according to the size of the value in that column. This kind ...