Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Number of rows returned in a sqlite statement

Is there any easy way to get the number of rows returned by a sqlite statement? I don't want to have to go through the process of doing a COUNT() first. Thanks.

like image 861
Christopher Brady Avatar asked May 12 '10 20:05

Christopher Brady


People also ask

How do I find 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 we limit which rows are returned by a query?

The SQL LIMIT clause restricts how many rows are returned from a query. The syntax for the LIMIT clause is: SELECT * FROM table LIMIT X;. X represents how many records you want to retrieve. For example, you can use the LIMIT clause to retrieve the top five players on a leaderboard.

How many rows can SQLite hold?

The theoretical maximum number of rows in a table is 264 (18446744073709551616 or about 1.8e+19). This limit is unreachable since the maximum database size of 281 terabytes will be reached first.

How do I limit the number of rows returned in SQL Server?

If you don't need to omit any rows, you can use SQL Server's TOP clause to limit the rows returned. It is placed immediately after SELECT. The TOP keyword is followed by integer indicating the number of rows to return. In our example, we ordered by price and then limited the returned rows to 3.


2 Answers

On each call to sqlite_step, increment a variable by 1.

If you want the row count in advance, then there's no easy way.

like image 141
dan04 Avatar answered Nov 03 '22 01:11

dan04


To count all entries in a table, you can use the following SQL statement:

SELECT COUNT(*) FROM "mytable" where something=42;

Or just the following to get all entries:

SELECT COUNT(*) FROM "mytable";

In case you have already done the query, and just want the number of entries returned you can use sqlite3_data_count() and sqlite3_column_count() depending on what you want to count.

like image 23
Claus Broch Avatar answered Nov 03 '22 01:11

Claus Broch