-3

I am making a pagination function, here is my case:

1 table (example)

id | title | date | details

Now, I want to retrieve two different results from this table (example)

  1. Count all of the rows (for the total count of all the lists)
  2. I will only show every 10 list per page.

My current code is, I have 2 separated queries for 1 and 2, so it is like 2 connections, my question is, can this be done with a single query and then retrieve both of 1 and 2 results? If so, what do I need to do? Any suggestion/s can help me!

Shadow
  • 33,525
  • 10
  • 51
  • 64
Dumb Question
  • 365
  • 1
  • 3
  • 14

1 Answers1

1

I think,

This will help you.

Step 1: Get the all list from the table Step 2: Then count the records

Here is the single query to perform it.

SELECT COUNT(tmp.id) as cnt, tmp.* FROM (SELECT id, title, date, details FROM tablename) tmp
Anam Shah
  • 319
  • 1
  • 10