SQLite row counting

How to count the number of rows in a SQLite database table? I have a table called my_table and it has the columns name info and number .

+4
source share
2 answers

You can use rawQuery count(*) , which returns the number of rows in the table.

  cursor=db.rawQuery("Select count(*) from my_table;", null); 
+11
source

Use the SELECT COUNT(*) FROM " + DB_TABLE_PLACES to get the number of rows present in the table. Example

 private static final String DB_TABLE_PLACES = "my_table"; private SQLiteDatabase mDatabase; private long fetchPlacesCount() { String sql = "SELECT COUNT(*) FROM " + DB_TABLE_PLACES; SQLiteStatement statement = mDatabase.compileStatement(sql); long count = statement.simpleQueryForLong(); return count; } 
+5
source

Source: https://habr.com/ru/post/1398621/


All Articles