How to find the number of rows in an SQLite3 SELECT statement containing the COUNT() function in Python

Finding the number of rows from executing an SQLite3 SELECT statement containing COUNT() gives how many rows satisfied the conditions specified in the statement.

Solution for How to find the number of rows in an SQLite3 SELECT statement containing the COUNT() function in Python : You can use sqlite3.Cursor.fetchone() to find the number of rows in an SQLite3 SELECT statement Create a sqlite3.Cursor object using sqlite3.Connection.cursor() where sqlite3.Connection is a connection to a SQLite database.

Call sqlite3.Cursor.execute(sql_statement) where sql_statement is a valid SQL statement containing SELECT COUNT() and sqlite3.Cursor is the previously created sqlite3.Cursor object.

Create a tuple result using sqlite3.Cursor.fetchone() with sqlite3.Cursor as the previously created cursor object. Access the number of rows with result[0].


how-to-find-the-number-of-rows-in-an-sqlite3-select-statement-containing-the-count-function-in-python