ID EN
Aggregate Functions

COUNT(expr) [over_clause]

MySQL 8.4

COUNT(expr) [over_clause]

Syntax

MYSQL
SELECT student.student_name,COUNT(*)
       FROM student,course
       WHERE student.student_id=course.student_id
       GROUP BY student_name;

Examples

Example

Returns a count of the number of non-NULL values of expr in the rows retrieved by a SELECT statement. The result is a BIGINT value.

MYSQL
SELECT student.student_name,COUNT(*)
       FROM student,course
       WHERE student.student_id=course.student_id
       GROUP BY student_name;
Example 2

If there are no matching rows, COUNT() returns 0. COUNT(NULL) returns 0.

MYSQL
SELECT COUNT(*) FROM student;