Count Function in MySQL

Profile picture for user arilio666

In MySQL, the count() function is mainly used to return the count of an expression. The specified information within the function fetches all the rows or some rows of the specified condition. The function is a type of aggregate function with the return type BIGINT and returns 0 if it does not find any matching rows.

Syntax

SELECT count(exp) FROM TableName;

Example

Let us take an example table called 'emp.'

mysql count rows

  • Let us try to fetch the count of jobTitle from the emp table.
select count(jobTitle) from emp;

mysql count

  • Let us try to get distinct addresses from the 'emp' table.
select count(distinct address) from emp

how to count in mysql

  • Let us try to fetch count from the 'emp' table using the where condition.
select count(*) from emp where officeCode = 221

mysql column count

So this is how we can use the count function effectively and play around with it.

Tags