SQLite COUNT Function

SQLite COUNT Function is used to fetch the total count of an expression.

Syntax:

snippet
SELECT COUNT(aggregate_expression)
FROM tables
[WHERE conditions];

Syntax when you use MAX function with GROUP BY clause:

snippet
SELECT expression1, expression2, ... expression_n
COUNT(aggregate_expression)
FROM tables
[WHERE conditions]
GROUP BY expression1, expression2, ... expression_n;

Example1:

We have a table named "STUDENT", having the following data:

Sqlite Count function 1

Count all the number of students in the "STUDENT" table where AGE is greater than 22.

snippet
SELECT COUNT(*) AS "Number of students"
FROM STUDENT
WHERE AGE > 22;

Output:

Sqlite Count function 2

Example2:

Using GROUP BY clause with COUNT function:

Count the number of students with a specific name where the age is greater than 22 and group by the students by name.

snippet
SELECT NAME, COUNT(*) AS "Number Of Students"
FROM STUDENT
WHERE AGE > 22
GROUP BY NAME;

Output:

Sqlite Count function 3
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +