I want to make a request to the MySQL database, I need to get only 5 records from it, but at the same time I need to count the total number of records that satisfy my condition.
That is, I need the line of the user request to bring him to 1 page only 5 records, but the number of pages will have to be calculated from the total number of records found.
I understand that you can make a request without a limit, but then too much data will return to me, and if you make 2 requests: 1 receives the number of records, and the second receives 5 records, you will have to join the database 2 times and spend extra time searching again.
The question is whether it is possible to do this somehow in 1 SQL query or to minimize the cost of resources with 2 queries. Correct if something is not understood.
Thanks in advance for any help.
