mysql select n rows starting at row x loop to beginning of table if necessary

What is the best way to select a given number of rows starting at a given row number, looping to the beginning of the table if necessary?

The following does not work if the sum of $starting_offset and $limit is greater than the number of rows in the table:

FROM table
ORDER BY sort_order ASC
LIMIT $starting_offset, $limit

I need to always select $limit number of rows.

Read more here:

Content Attribution

This content was originally published by SuprMan at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: