Skip to main content

Posts

Showing posts with the label sql operations

Difference between WHERE and HAVING

1> WHERE Clause Filters rows before grouping. Works with non-aggregate conditions (like simple comparisons on columns). Eg : SELECT employee, bonus FROM emp_bonus WHERE bonus > 5000; 2>  HAVING Clause Filters groups after aggregation. Works with aggregate functions (SUM, AVG, MAX, MIN, COUNT). Eg : SELECT employee, SUM(bonus) FROM emp_bonus GROUP BY employee HAVING SUM(bonus) > 5000; 💡 In Short :  WHERE = "Which rows should I include in the group?" HAVING = "Which groups should I keep after aggregation?"