Skip to content Skip to sidebar Skip to footer

How To Get The Number Of Rows Of The Selected Result From Sqlite3?

I want to get the number of selected rows as well as the selected data. At the present I have to use two sql statements: one is select * from XXX where XXX; the other is select

Solution 1:

try this way

select (select count() from XXX) as count, * 
from XXX;

Solution 2:

SQL can't mix single-row (counting) and multi-row results (selecting data from your tables). This is a common problem with returning huge amounts of data. Here are some tips how to handle this:

  • Read the first N rows and tell the user "more than N rows available". Not very precise but often good enough. If you keep the cursor open, you can fetch more data when the user hits the bottom of the view (Google Reader does this)

  • Instead of selecting the data directly, first copy it into a temporary table. The INSERT statement will return the number of rows copied. Later, you can use the data in the temporary table to display the data. You can add a "row number" to this temporary table to make paging more simple.

  • Fetch the data in a background thread. This allows the user to use your application while the data grid or table fills with more data.


Solution 3:

select (select COUNT(0) 
            from xxx t1 
            where t1.b <= t2.b 
            ) as 'Row Number', b from xxx t2 ORDER BY b; 

just try this.


Solution 4:

You could combine them into a single statement:

select count(*), * from XXX where XXX

or

select count(*) as MYCOUNT, * from XXX where XXX

Solution 5:

Once you already have the select * from XXX results, you can just find the array length in your program right?


Post a Comment for "How To Get The Number Of Rows Of The Selected Result From Sqlite3?"