I am using SQLITE in android and I am having an issue I want to get the total count of row when limit is applied. For example if I apply limit of 100 for pagination but there are around 2000 data. I want to make a query where i can get only the 100 rows but the count should return 2000 ie total number of rows. Things I have tried
SELECT * ,count(*) OVER() AS full_count FROM table LIMIT 0,100
SELECT SQL_CALC_FOUND_ROWS, * FROM table LIMIT 0,100
I know there are nested query which will work but I have around 2 million rows and for pagination, I am only fetching 100 rows at a time. So nested query would slow the process completely.
Use a CTE to get the total number of rows:
with cte as(
select count(*) total from table
)
select *, (select total from cte) total
from table limit 0, 100
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.