SQLite COUNT() Function
The COUNT() Function
COUNT() returns the number of rows. COUNT(*) counts all the rows.
This example counts the products:
Count a Column
COUNT(column_name) counts the rows where the column is not NULL:
Count With WHERE
This example counts the products with a price greater than 20:
Count the Different Values
Use DISTINCT to count each value only once. This example counts the different prices:
Use an Alias
Example
Give the result column a name:
SELECT COUNT(*) AS NumberOfProducts
FROM Products;
Try it Yourself »
Count for Each Group
This example counts the products in each category:
Example
SELECT CategoryID, COUNT(*) AS Products
FROM Products
GROUP BY CategoryID;
Try it Yourself »