Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the number of rows of the selected result from sqlite3?

Tags:

sqlite

count

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 count(*) from XXX where XXX;  

Can it be realised with a single sql string?

I've checked the source code of sqlite3, and I found the function of sqlite3_changes(). But the function is only useful when the database is changed (after insert, delete or update).

Can anyone help me with this problem? Thank you very much!

like image 495
user26404 Avatar asked Mar 02 '09 08:03

user26404


People also ask

How do I see the number of rows in SQLite?

The COUNT(*) function returns the number of rows in a table, including the rows including NULL and duplicates.

How do you count rows of a query result?

To counts all of the rows in a table, whether they contain NULL values or not, use COUNT(*). That form of the COUNT() function basically returns the number of rows in a result set returned by a SELECT statement.

How do I find the number of rows selected in SQL Server?

The SQL COUNT() function returns the number of rows in a table satisfying the criteria specified in the WHERE clause. It sets the number of rows or non NULL column values. COUNT() returns 0 if there were no matching rows.


1 Answers

try this way

select (select count() from XXX) as count, *  from XXX; 
like image 96
Artem Aleksandrov Avatar answered Sep 29 '22 04:09

Artem Aleksandrov