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.
COUNT(column_name) COUNT(*)
- COUNT(column_name)
counts non-NULL values in that column.
- COUNT(*)
counts all rows, including those with NULLs.
-- 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';
The COUNT()
function is very useful for summarizing data quickly.
Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!