B4J Question SQLite Database....How can I find the the number of rows in a table.

embedded

Active Member
Licensed User
Longtime User
How can i find number of rows in a table in Sqlite Database....Thanks in Advance..
 

Roycefer

Well-Known Member
Licensed User
Longtime User
If you want to do the same without having to know a column name from the table, you can use
B4X:
SELECT COUNT(rowid) FROM Kunden
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
If you want to do the same without having to know a column name from the table
Another way (and the SQL way) is
B4X:
SELECT COUNT(*) FROM Kunden
When you use a column name instead of *, SQL will return all the rows where the value of the column name is not NULL. That count may be less than the actual count of rows in a DB. In the specific case of SQLite, rowid may not be NULL and therefore return the correct number of rows. But instead of guessing if a certain column has NULL values or not, one can always use *.
 
Upvote 0

Roycefer

Well-Known Member
Licensed User
Longtime User
Counter-intuitively,
B4X:
SELECT COUNT(*) ...
is faster than
B4X:
SELECT COUNT(rowid) ...
. Using a declared column is even slower than both.

The difference is microscopic and they are both very fast. But it was an unexpected finding. It goes to show, you should always test your speculations.
 
Upvote 0
Top