Deepak Rathore
Deepak Rathore

Reputation: 627

How to get total no. of rows , when using LIMIT in SQLite

I have a table like this.

test

id      name

1       first
2       second
3       third
4       fourth
5       fifth

I am using pagination concept in my Android application .

I have to use a LIMIT of 3 rows . But also total no. of rows in this table .

How can i do this is SQLite database in one query ?

Upvotes: 2

Views: 3221

Answers (1)

antonio
antonio

Reputation: 18262

If you want to get the total count for each retrieved row you can try the following (based on your comment):

SELECT id, name, c.total_rows
    FROM test t, (
        SELECT count(*) total_rows
            FROM test
        ) c 
    LIMIT 3

Upvotes: 2

Related Questions