SQLite COUNT

The SQLite COUNT function calculates and returns the number of values in a set. Also SQLite COUNT function can count the number of rows with non-null values.

Syntax

Here is the syntax of SQLite COUNT function:

SELECT COUNT(*) FROM table_name;

Syntax of SQLite COUNT function with non-null values:

SELECT COUNT(column_name) FROM table_name;

Example

Table of books

ID NAME PRICE
1 SQLite 10
2 SQL 20
3 PL/SQL 30
4 PHP NULL
5 Python 20
6 HTML 40

Basic example

SELECT COUNT(*) FROM books;

Count result: 6

The first example shows how to get the total rows from the books table.

COUNT with non-null values

SELECT COUNT(PRICE) FROM books;

Count result: 5

The second example shows how to get the total rows with non-null values. Inside the brackets of COUNT is written the name of the column to be counted according to non-null values.