MYSQL Tutorial



MySQL COUNT()


MySQL COUNT() Function

The COUNT() function in MySQL is used to count the number of rows that match a specified condition. It is commonly used to get the total number of records in a table or to count rows that satisfy certain criteria.

Syntax:

COUNT(column_name)
COUNT(*)
  

- COUNT(column_name) counts non-NULL values in that column.
- COUNT(*) counts all rows, including those with NULLs.

Example Queries:

-- Count all employees
SELECT COUNT(*) AS total_employees FROM employees;

-- Count employees with a non-null email
SELECT COUNT(email) AS employees_with_email FROM employees;

-- Count employees from 'Sales' department
SELECT COUNT(*) AS sales_count FROM employees WHERE department = 'Sales';
  

Try it yourself:


The COUNT() function is very useful for summarizing data quickly.


🌟 Enjoyed Learning with Us?

Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!

Leave a Google Review