SQL for specific page

Asked

Viewed 36 times

0

I’m making my own paging code from a table of records, and in my case I don’t want only the requested page to come by AJAX instead of all pages to be manipulated by Javascript.

The information of the quantity of records (Required to calculate the number of pages) I know I can get with count(), but the select do not know how I can get only the page I need, for example, in the situation where my page will have only 10 records I know I can get the first page limiting the result with LIMIT 10 in my query, but what about the other pages? How do I get a certain range of results after my first SQL page? For example I only want 10 records after the first 10. Have this feature in SQL?

1 answer

2


In Mysql, you can continue using LIMIT to do this. LIMIT can work with initial position and number of records. Here are some examples:

SELECT * FROM minha_tabela ORDER BY id LIMIT 0, 15
SELECT * FROM minha_tabela ORDER BY id LIMIT 15, 15
SELECT * FROM minha_tabela ORDER BY id LIMIT 30, 15

In this example, the 15 at the end refers to the amount of records to return, and the first number and position of the initial record

Browser other questions tagged

You are not signed in. Login or sign up in order to post.