WHERE vs HAVING | Database Interview | Skill-Lync Resources
Easy Database Systems SQL Fundamentals

What is the difference between WHERE and HAVING clauses in SQL?

Answer

WHERE filters rows before grouping and aggregation - it cannot use aggregate functions. HAVING filters groups after GROUP BY and aggregation - it can use aggregate functions. Example: WHERE filters individual orders (WHERE amount > 100), HAVING filters customer groups (HAVING SUM(amount) > 1000). Execution order: FROM -> WHERE -> GROUP BY -> HAVING -> SELECT -> ORDER BY. Use WHERE when possible for better performance.

Master These Concepts with IIT Certification
IIT Certified

Master These Concepts with IIT Certification

175+ hours of industry projects. Get placed at Bosch, Tata Motors, L&T and 500+ companies.

Relevant for Roles

Software Engineer Backend Developer Data Analyst