Interview Question

What is HAVING clause?

HAVING filters groups; WHERE filters rows.

💡 Concept ✅ Quick Revision 🗃️ SQL

Answer

HAVING filters groups after grouping and aggregate calculation. • It is commonly used with aggregate conditions. • WHERE filters individual input rows before groups are formed. • A query can use both WHERE and HAVING for different stages.

💡 SQL Example

SELECT department_id, COUNT(*) FROM employees GROUP BY department_id HAVING COUNT(*) >= 3;

Result

10 | 4 20 | 3

⚡ Quick Revision

HAVING filters groups; WHERE filters rows.