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.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e68e46-45ced.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e68e46-45ced.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?