How to return the number of records that meet the query criteria before paging in a paging query?

how to check the total number of records returned by answering query conditions in query pagination:

select top 10 * 
from (select row_number() 
over(order by id asc) as rownumber,* 
from com_system_menu) temp_row
where rownumber>((2-1)*10);

the number of records I want is all the records before Where rownumber > ((2-1) * 10) above?


I don't know what database you are using.

if it is MySQL, there is a feature specifically suitable for this scenario: FOUND_ROWS . For example, execute a query on a table foobar as follows

SELECT *, COUNT(*) OVER () AS total_rows FROM foobar WHERE ...... LIMIT 10;

Note 2 the above query for em PG returns up to 10 rows of data, where the column total_rows has the same value, which is the total number of rows when the query does not contain a LIMIT clause.

Menu