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.'
- Let us try to fetch the count of jobTitle from the emp table.
select count(jobTitle) from emp;
- Let us try to get distinct addresses from the 'emp' table.
select count(distinct address) from emp
- Let us try to fetch count from the 'emp' table using the where condition.
select count(*) from emp where officeCode = 221
So this is how we can use the count function effectively and play around with it.
- Log in to post comments