mardi 10 novembre 2020

How do I select random rows from a table with limit and no duplicates?

I want to select 100 random rows from a mysql table. That is easy.

SELECT * FROM table_name ORDER BY RAND() LIMIT 100, 1;

When the user clicks a button I want the next 100 random rows but not any of the first 100 rows.

SELECT * FROM table_name ORDER BY RAND() LIMIT 100, 101;

And again.

SELECT * FROM table_name ORDER BY RAND() LIMIT 100, 201;

The problem is that the above query select duplicates. Is it possible to select only random rows that have not been selected before?




Aucun commentaire:

Enregistrer un commentaire