GROUP BY and HAVING in MySQL

Published September 25, 2026 By Sai Sree Ram Gundepudi

GROUP BY

SELECT department, COUNT(*) FROM employees GROUP BY department;

HAVING

SELECT department, COUNT(*) AS total 
FROM employees
GROUP BY department
HAVING total > 5;

Was this solution helpful?

Your feedback helps improve our technical knowledge repository.

Share this article