Javatpoint Logo
Javatpoint Logo

MariaDB COUNT() Function

In MariaDB database, COUNT function is used to return the count of an expression.

Syntax:

The COUNT () Function counts only NOTNULL values.

Example:

We have a table "Students", having the following data:

MariaDB Count function 1

Count "student_id" from "Students" table:

Output:

MariaDB Count function 2

It shows 8 rows of student_id is available in "Students" table.

Now count "admission_date" from "Students" table:

Output:

MariaDB Count function 3

It shows only 7 rows of "admission_date" column because 1 field is NULL.


COUNT () Function with Single Expression

Count the number of students where "student_name" is "Ajeet" or "Kanchan".

Output:

MariaDB Count function 4

COUNT () Function with Distinct Clause

DISTINCT Clause is used with COUNT () function to prevent duplicate counting. It consists of only original records.

Output:

MariaDB Count function 5

It shows only 2 counts because "student_name" Ajeet has duplicate entries in the table.






Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA