When writing a query for paging on a web page what is the least expensive method to get a total row count? Is there a way to do this without running a query twice – one for the total and the next for the limit?
Using MySQL
Example: (I want to know if there is a less expensive way)
Get Count
SELECT COUNT(*) FROM table
Get Paging
SELECT mycolumns FROM table LIMIT 100
How can I get the total count without running 2 queries.
This will give you an additional column called
Countin each row that contains the total number of rows: