I have been having this problem for a long time and I can not resolve it.
I have a page with infinite scroll that returns a few lines from the database, but the results most often repeat. I am using the following query whenever the scroll reaches the bottom of the page:
SELECT TOP 10 * FROM table_name ORDER BY NEWID()
To remedy the situation I include a mask, which does not return the results already displayed on the page, for example:
SELECT TOP 10 * FROM table_name WHERE id NOT IN ($resultados_ja_exibidos) ORDER BY NEWID()
But the time comes for the query above to be slow because of the large number of ids that need to be checked before returning the results.
How do I optimize this function?