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. Key Where Having
1 Definition WHERE 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.
2 Execution As 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.
3 GroupBy compatibility WHERE clause can be used with GroupBy clause in a SQL query. On other hand, Having clause does not have compatibility with GroupBy clause.
4 Row selection WHERE clause select the rows before grouping of result. On other hand Having clause selects the rows after grouping.
5 Aggregate Function WHERE clause cannot contain the aggregate function. On other hand HAVING clause can contain the aggregate function.
Updated on: 2020-06-09T08:09:22+05:30

365 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements