What is the difference between a “where” clause and a “having” clause?
Sapna Malik
1. The Where can be used without the GROUP BY clause. The HAVING clause cannot be used without the GROUP BY clause. 2. The WHERE clause selects rows before grouping. The HAVING clause selects rows after grouping. 3. The WHERE clause cannot contain aggregate functions. The HAVING clause can contain aggregate functions. 4. The Having can used only with the select statement
Both WHERE and HAVING clauses are used to filter the data. But WHERE Clause can't be used with Aggregate Functions, so HAVING Clause is introduced. The HAVING Clause is used to filter data (returned by GROUP BY Statement) after GROUP BY Statement and The WHERE Clause is used to filter data (returned by SELECT Statement) before GROUP BY Statement.* The use of WHERE Clause after GROUP BY Statement is restricted.* The use of HAVING Clause before GROUP BY Statement is restricted.