Now, suppose based on the above table you want to count total number of rows in this table, then you can do it as follows −
Mysql> insert into employee_tbl values(5, 'Zara', DATE(''), 350) Mysql> insert into employee_tbl values(5, 'Zara', DATE(''), 300) Mysql> insert into employee_tbl values(4, 'Jill', DATE(''), 220) Mysql> insert into employee_tbl values(3, 'Jack', DATE(''), 100) Mysql> insert into employee_tbl values(3, 'Jack', DATE(''), 170) Mysql> insert into employee_tbl values(2, 'Ram', DATE(''), 220) Mysql> insert into employee_tbl values(1, 'John', DATE(''), 250) Assume we have created another table named employee_tbl and inserted records in it as follows – | First_Name | Last_Name | COUNTRY | COUNT(*) |įollowing is another example of this function. Mysql> SELECT First_Name, Last_Name, COUNTRY, COUNT(*) FROM MyPlayers GROUP BY country You can also use the GROUP BY clause along with this function – Insert into MyPlayers values(7, 'James', 'Anderson', 15, 'England') įollowing query returns the number of records in the table – Insert into MyPlayers values(6, 'Ravindra', 'Jadeja', 15, 'India') MySQL COUNT() Function Insert into MyPlayers values(5, 'Rohit', 'Sharma', 25, 'India') Insert into MyPlayers values(4, 'Virat', 'Kohli', 50, 'India') Insert into MyPlayers values(3, 'Kumara', 'Sangakkara', 25, 'Sri Lanka') Insert into MyPlayers values(2, 'Jonathan', 'Trott', 50, 'SouthAfrica') Insert into MyPlayers values(1, 'Shikhar', 'Dhawan', 95, 'India') Now, we will insert 7 records in MyPlayers table using INSERT statements − This table stores the first and last names, country, scores in an exhibition match of a player. Assume we have created a table with name MyPlayers in MySQL database using CREATE statement as shown below – Syntaxįollowing is the syntax of this function –įollowing is an example demonstrating the usage of this function. If you invoke this function as COUNT(*) this function returns the number of records in the specified table irrespective of the NULL values. If the specified row(s) doesn’t exist this function returns 0. The MySQL COUNT() function is used to calculate the number of non-NULL values in a particular column. MySQL provides a set of aggregate functions that perform operations on all the entities of the column of a table considering them as a single unit. In general, aggregation is a consideration of a collection of objects that are bound together as a single entity.