Difference between Where and Having

Both Where and Having are the two keywords used in SQL query to filter and summarize the data that is retrieved from database based on given condition.

On the basis of features of both keywords we can distinguish between Where and Having as follows −

Sr. No.KeyWhereHaving
1DefinitionWHERE clause in SQL query specifies search conditions for the rows returned by the it and limits rows to a specific row-set. In case if user wants to get the particular records based on some specific classification or condition then using ‘where’ clause is useful.The WHERE clause is used to specify the required condition (on aggregate values) while selecting the rows of a table.
2ExecutionAs per the order of execution of clauses, the WHERE clause is executed before the execution of the GROUPBY CLAUSE and, after the execution of the FROM clause.On other hand HAVING clause is executed after groups are created.
3GroupBy compatibilityWHERE clause can be used with GroupBy clause in a SQL query.On other hand, Having clause does not have compatibility with GroupBy clause.
4Row selectionWHERE clause select the rows before grouping of result.On other hand Having clause selects the rows after grouping.
5Aggregate FunctionWHERE clause cannot contain the aggregate function.On other hand HAVING clause can contain the aggregate function.
Updated on 09-Jun-2020 08:09:22