Database Management MySQL Subjective
Oct 01, 2025

What is the difference between WHERE and HAVING clauses?

Detailed Explanation

WHERE:
• Filters rows before grouping
• Cannot use aggregate functions
• Applied to individual rows

HAVING:
• Filters groups after GROUP BY
• Can use aggregate functions
• Applied to grouped results

Example:
SELECT department, COUNT(*)
FROM employees
WHERE salary > 50000
GROUP BY department
HAVING COUNT(*) > 5;

Discussion (0)

No comments yet. Be the first to share your thoughts!

Share Your Thoughts
Feedback