MySQL COUNT() Examples Sample Table: employees id | name | department | salary
1 | Rohan | HR | 30000
2 | Priya | IT | 45000
3 | Aarav | IT | 50000
4 | Simran | Finance | NULL
5 | Krish | HR | 28000
1. Count all rows SELECT COUNT(*) FROM employees; 2. Count non-NULL salary SELECT
COUNT(salary) FROM employees; 3. Count employees in IT SELECT COUNT(*) FROM
employees WHERE department = 'IT'; 4. Count employees per department (GROUP BY) SELECT
department, COUNT(*) AS total FROM employees GROUP BY department; 5. Count departments
with more than 1 employee (HAVING) SELECT department, COUNT(*) AS total FROM employees
GROUP BY department HAVING COUNT(*) > 1; 6. Count distinct departments SELECT
COUNT(DISTINCT department) FROM employees;